Using unmanaged code, how can I find a type that has a given custom attribute assigned to it?
Posted
by Andrew
on Stack Overflow
See other posts from Stack Overflow
or by Andrew
Published on 2010-04-07T07:18:37Z
Indexed on
2010/04/07
7:23 UTC
Read the original article
Hit count: 276
I had thought I could enumerate the types using IMetaDataImport.EnumTypeDefs and for each of the tokens returned, call IMetaDataImport.EnumCustomAttributes.
This works, in so much as I get an array of mdCustomAttribute tokens. Using these tokens I can get a metadata token representing the Type of the returned custom attribute, by calling IMetaDataImport.GetCustomAttributeProps.
Comparing my results against ILDASM, I can see that this matches the "CustomAttribute Type" that ILDASM reports. However, I cannot work out how to determine the "CustomAttributeName" that ILDASM reports. This is what I really want!
While I would be interested in knowing how to get the CustomAttributeName, I would settle for an alternate approach to solving the problem.
© Stack Overflow or respective owner