[Mono-list] Method Attributes
Duncan Mak
duncan@ximian.com
Sat, 16 Aug 2003 19:06:57 -0400
On Sat, 2003-08-16 at 15:17, Hamza Karamali wrote:
> Hi,
>
> If I attach a custom attribute called "myAttribute" to a certain method,
> how can I check in Mono (while the method is being compiled) whether a
> method has this attribute? Is there a function that will search the
> metadata for the attribute if I pass it the name of the attribute? If
> not, how would I go about doing this?
>
You can use Reflection to do this. You call GetType to get the Type
definition; with that, you can call GetCustomAttributes to get
Type-associated attributes, or call GetMember (and others) to get
MemberInfos of a Type. You can then query the MemberInfos with
GetCustomAttributes and get member-associated attributes.
Duncan.