I have a generic class and a derived class as following.
public class GenericClass<T> { ... }
public class DerivedClass : GenericClass<SomeType> { ... }
How do I find the derived class via reflection? I have tried both ways below, but doesn’t seem to work.
System.Reflection.Assembly.GetExecutingAssembly().GetTypes().Where(t => typeof(GenericClass<>).IsAssignableFrom(t));
System.Reflection.Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(GenericClass<>));
1 Answer