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.
Sorry, this was a case of RTFM. The attribute returned by
GetCustomAttributePropsis not a typedef token, but amdMethodDeformdMemberReftoken.For mdMethodDef tokens, you use
IMetaDataImport.GetMethodPropsto find the typeDef token and for mdMemberRefs, it is a slightly longer path, but you start withIMetaDataImport.GetMemberRefProps.The moral of the story is to pay attention to what sort of tokens these functions are returning!