This project is read-only.

Easy way to readout all custom attribute usages?

Aug 8, 2011 at 11:53 AM

Is there an easy way to readout all custom attribute usages? Is there something like Visit(IAttributeReference) or do I really have to Visit all attribute targets ( and check for any attributes?

Best regards,


Aug 8, 2011 at 3:30 PM

Visit(ICustomAttribute customAttribute) is the overload you want. When this visitor is dispatched via a BaseTraverser, you'll visit all custom attributes usages. (Of course, you could also just override TraverseChildren(ICustomAttribute instead.)

Aug 10, 2011 at 8:18 AM

Thank you. Unfortunately there is far too less context information in ICustomAttribute to find out where exactly the attribute usage has appeared. Is there any way to find out the assembly/type/method/parameter/whatsoever the attribute got applied to?

In the meantime we are visiting each and every element where an attribute could be used and readout all the attributes there : (


Best regards,


Aug 10, 2011 at 6:28 PM

At the moment your only choice is to track this information during the traversal. It probably makes sense to augment the object model so that every custom attribute has a "parent pointer".

The current object model assumes that you mostly ask "What are the attributes of foo?", rather than "Given a foo attribute, which definition does it qualify?".

Aug 11, 2011 at 8:08 AM

I see, thank you. We are now using a preorder/postorder visitor combination in order to track context information.

Thanks again for your quick bugfix and your help in all threads!

Best regards,