I would like to create a method that returns a type (or IEnumerable of types) that implements a specific interface that accepts a type parameter, however I want to search for this parameter of a generic type. This is easier to demonstrate as an example:
The signature of the method I want:
public IEnumerable<Type> GetByInterfaceAndGeneric(Type interfaceWithParam, Type specificTypeParameter)
And if I have the following objects
public interface IRepository<T> { };
public class FooRepo : IRepository<Foo> { };
public class DifferentFooRepo : IRepository<Foo> {};
Then I want:
var repos = GetByInterfaceAndGeneric(typeof(IRepository<>), typeof(Foo));
and get IEnumerable containing the types FooRepo
and DifferentFooRepo
.
This is very similar to this question , however, using this example, I would like to search both IRepository<>
, and User
.
source
share