How do I get all types that implementing a specific open generic type?
For instance:
public interface IUserRepository : IRepository
You can use the following code to get all types that implement IRepository<> interface:
List typesImplementingIRepository = new List();
IEnumerable allTypesInThisAssembly = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type type in allTypesInThisAssembly)
{
if (type.GetInterface(typeof(IRepository<>).Name.ToString()) != null)
{
typesImplementingIRepository.Add(type);
}
}