mardi 5 novembre 2019

Get the implicitly instantiated generic types in from an assembly?

I'm trying to use C# reflection to retrieve all the types from an assembly (let's say: from the "ExecutingAssembly"), I can retrieve all the explicitly defined types including the generic types I define in the assembly. But I don't seem to be able to retrieve the implicitly instantiated generic types (the concrete version).

For example, var types = Assembly.GetExecutingAssembly().GetTypes(); this would retrieve all the explicitly defined types (classes, structs that are defined in this assembly, including the generic ones, such as class MyGenericClass<T>).

However, in the same assembly, I actually use MyGenericClass<int> as the concrete type in my code to actually instantiate objects (such as: MyGenericClass<int> myObject;), but this concrete MyGenericClass<int> type doesn't seem to be retrievable by the code above.

I'm wondering if any instantiated generated types are actually retrieveable from the assembly, so I may use that type to do some code generation work later.

If they are not retrievable, any design suggestions?

Thank you in advance!





Aucun commentaire:

Enregistrer un commentaire