> Not sure if this qualifies as "advanced", but I'm having trouble
> decorating in a derived class events/properties of the inherited class
> with additional attributes.  I've included some code to show what I
> mean - I want to do this without shadowing.  So, in this example I
> want DeviceB to be able to add attributes to an event from DeviceA.
> So, if it's not something obvious, are there any workarounds or best
> practices for this situation?

In your example, use Attribute.GetCustomAttributes rather than
member.GetCustomAttributes (where member is an MemberInfo, e.g. an
EventInfo). For some reason, MemberInfo.GetCustomAttributes does not
search the inheritance chain correctly even if you specify "true" for
the "inherit" parameter.

I've yet to find out why this isn't documented in
MemberInfo.GetCustomAttributes... Instead, it's in the docs for
EventInfo:

"Calling ICustomAttributeProvider.GetCustomAttributes on EventInfo
when the inherit parameter of GetCustomAttributes is true does not
walk the type hierarchy. Use System.Attribute to inherit custom
attributes."

Fabian

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to