The MSDN Documentation: MemberInfo.GetCustomAttibutes Method (Type, Boolean) states in the remarks:
This method ignores the inherit parameter for properties and events. To search the inheritance chain for attributes on properties and events, use the appropriate overloads of the Attribute.GetCustomAttributes method.
This basically means that this implementation’s second parameter (bool inherit) is ignored for event members and property members. However, calling the Attribute.GetCustomAttributes(MemberInfo,Type,bool) variety of this operation does not.
What puzzles me is the design of this.
Why would they seemingly ignore the inherit attribute arbitrarily on 2 forms of member types?
If anyone could shed some light on this I’d be greatly appreciative.
This is definitely confusing. The strict answer is that properties and events are not inherited so the
inheritedparameter has no meaning. The reference is ECMA 335 CLI Specification section 8.10.3.The specification says nothing about how a compiler should implement this. In the case of C# properties are implemented via separate getter and setter methods which can be declared
virtualandoverride. Likewise, for events there are separate addhandler and removehandler methods.So the simple answer is that properties and events are strictly metadata devoid of any implementation according to the specification. That is why they cannot be inherited in the same sense that methods are.