I am trying to write a method using reflection to return all classes that are subclasses of a class that uses generics, without being limited by the generic type. So for example, in EF I want to find all mapping classes. The classes are setup like:
public class clientMap : EntityTypeConfiguration<Client> {}
I want to find all classes in my assembly that is a subclass of of EntityTypeConfiguration<T>
, without specifying Client
as T specifically. I want to return the entity type configuration for all classes in my application without hardcoding it.
Without generics I would loop through the types in the assembly, check if type.IsSubclassOf(typeof(BaseClass))
, however I am not sure how to do this when dealing with generics.
I believe that you want something like this:
These tests pass:
as far as I understood your case the following should be enough