/// <summary> /// Gets the implementations of the type specified by the type parameter and located in the assemblies /// filtered by the predicate. /// </summary> /// <typeparam name="T">The type parameter to find implementations of.</typeparam> /// <param name="predicate">The predicate to filter the assemblies.</param> /// <param name="useCaching"> /// Determines whether the type cache should be used to avoid assemblies scanning next time, /// when the same type(s) is requested. /// </param> /// <returns>Found implementations of the given type.</returns> public static IEnumerable <Type> GetImplementations <T>(Func <Assembly, bool> predicate, bool useCaching = false) { Type type = typeof(T); if (useCaching && ExtensionManager.types.ContainsKey(type)) { return(ExtensionManager.types[type]); } List <Type> implementations = new List <Type>(); foreach (Assembly assembly in ExtensionManager.GetAssemblies(predicate)) { //var assName = assembly.GetName().FullName.ToLower().Contains("services"); foreach (Type exportedType in assembly.GetExportedTypes()) { if (type.GetTypeInfo().IsAssignableFrom(exportedType) && exportedType.GetTypeInfo().IsClass) { implementations.Add(exportedType); } } } if (useCaching) { ExtensionManager.types.Add(type, implementations); } return(implementations); }
public static IEnumerable <Type> GetImplementations <T>(Func <Assembly, bool> predicate) { List <Type> implementations = new List <Type>(); foreach (Assembly assembly in ExtensionManager.GetAssemblies(predicate)) { foreach (Type type in assembly.GetTypes()) { if (typeof(T).GetTypeInfo().IsAssignableFrom(type) && type.GetTypeInfo().IsClass) { implementations.Add(type); } } } return(implementations); }