.net - GetCustomAttributes?
Sep 13, 2010<AttributeUsage(AttributeTargets.Property)> _
Private Class CustomAttrib
Inherits Attribute
[code].....
<AttributeUsage(AttributeTargets.Property)> _
Private Class CustomAttrib
Inherits Attribute
[code].....
I am struggling to get the syntax for the reflection call GetCustomAttributes ... at least I don't seem to be able to get hold of the custom attribute which I've decorated a particular method with. The complicating factor maybe that I have passed that method into an extension method as a generic delegate. (The other, more likely, complicating factor is that I'm not sufficiently familiar with reflection or what happens when you pass a method as a parameter like this!)
The code appears to run, and when I step it, the count returned from the GetCustomAttributes is 1. I can't work out how to get hold of that custom parameter
[Code]...
I am struggling to retrieve custom attributes from a method. As you can see, the method ProcessXML has a custom attribute. The method itself gets passed into an anonymous delegate and then, in that context, I'm looking to get its custom attributes, but I'm not sure quite how to do it.
Here's my code
Public Sub UpdateXML()
Dim errors = New Errors
Dim xml = <testxml>
[code]....
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 ttribute.GetCustomAttributes(MemberInfo,Type,bool) variety of this operation does not. Why would they seemingly ignore the inherit attribute arbitrarily on 2 forms of member types?
View 1 Replies