0

I would like to iterate all classes that derive from a generic base class. My problem is that I do not know how (if it is possible) to get the generic base class as a Type.

I can do:

Type myGeneric = typeof(MyGeneric<MyConcreteA,MyConcreteB>);

I cannot do:

Type myGeneric = typeof(MyGeneric<TMyA,TMyB>));

Is something like this possible?

foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
    foreach (Type type in asm.GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract))
    {
        if (type.IsSubclassOf(myGeneric))
user229044
  • 232,980
  • 40
  • 330
  • 338
commodore73
  • 61
  • 2
  • 11

0 Answers0