Reputation: 9508
If I recall it correctly, Attribute.GetCustomAttributes
was initially introduced because MemberInfo.GetCustomAttributes
had a bug for fields and events.
Now I'm trying to find any links to this issue, to understand if they're completely interchangeable in modern .NET Framework (if this bug was fixed), but I can't. I may be totally wrong about it, then please explain the correct history, and why there are two ways of doing the same thing?
Upvotes: 2
Views: 149
Reputation: 9508
I have missed this remarks section in documentation, which explains it all:
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.
And I was wrong about fields. This issue is only for properties and events.
Hope this question will improve this issue googlability.
Upvotes: 2