HowTo: Generic instances

Topics: Metadata Model
Aug 5, 2011 at 6:52 AM

I want to detect all generic type parameter instances, because I'm not 100% sure if I'm using the right terminology, here are some examples:

a) on type level:

class Foo : Base<FindThisType>

class Foo : IBase<List<FindThisType>>

interface Foo : IBase<FindThisType>

b) on operation level:

IList<FindThisType> test = new LinkedList<FindThisTypeToo>();


c) on type level, constraints

class Foo : Base <T> where T : FindThisType


Is there a convenient way to get all of them? Which Visit() method(s) do I have to handle? There are many methods with very similar names, and I can't really find details in the documentation. Are there any example pages with "this is a generic type instance reference" and "this is a generic parameter", etc.?

Best regards.


Aug 5, 2011 at 8:49 PM

Override the MetadataVisitor methods Visit(IGenericParameter) and Visit(IGenericParameterReference) and use a MetadataTraverser to dispatch the visitor on the object model.

Aug 8, 2011 at 6:58 AM

FindThisType is a concrete type and not a generic parameter. Something like int, string, MyClass, etc. So IGenericParameter is not suitable, the other method is not even existing in my version of CCI : (


Best regards,


Aug 8, 2011 at 8:20 PM

Visit(IGenericParameter) will get you constraints as well, since those can be reached via a property on IGenericParameter.

I don't quite follow your remark about "the other method" and your version of CCI? Could you explain some more?