Hello!
I'm trying to determine all GenericTypeInstances in an assembly.
For example,
namespace TestProgram
{
public class TestProgram
{
public struct GenericType<T>
{
public T mGeneric;
public int mInt;
public T mOtherGeneric;
}
public static Foo()
{
var instance1 = new GenericType<int>();
var instance2 = new GenericType<char>();
}
public static int Main()
{
Foo();
return 0;
}
}
}
I'm looking for a mechanism to ask, 'for this assembly, give me all generic type instances' and I would expect:
- valuetype TestProgram.TestProgram.GenericType`1<int32>
- valuetype TestProgram.TestProgram.GenericType`1<char>
The only approach I can think of currently is to inspect the IL across all method bodies and then if they refer to a generic type definition, that to a GenericTypeInstance and inspect the GenericArguments. But if there is a faster solution I am very interested.
Thanks and all the best,
Kev