public static Type GetImplementation <T>(Func <Assembly, bool> predicate) { IEnumerable <Type> implementations = ExtensionManager.GetImplementations <T>(predicate); if (implementations.Count() == 0) { throw new ArgumentException("Implementation of " + typeof(T) + " not found"); } return(implementations.FirstOrDefault()); }
public static IEnumerable <T> GetInstances <T>(Func <Assembly, bool> predicate) { List <T> instances = new List <T>(); foreach (Type implementation in ExtensionManager.GetImplementations <T>()) { T instance = (T)Activator.CreateInstance(implementation); instances.Add(instance); } return(instances); }
/// <summary> /// Gets the new instances (using constructor that matches the arguments) of the implementations /// of the type specified by the type parameter and located in the assemblies filtered by the predicate /// or empty enumeration if no implementations found. /// </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 instance(s) of the same type(s) is requested. /// </param> /// <param name="args">The arguments to be passed to the constructors.</param> /// <returns>The instances of the found implementations of the given type.</returns> public static IEnumerable <T> GetInstances <T>(Func <Assembly, bool> predicate, bool useCaching = false, params object[] args) { List <T> instances = new List <T>(); foreach (Type implementation in ExtensionManager.GetImplementations <T>(predicate, useCaching)) { if (!implementation.GetTypeInfo().IsAbstract) { T instance = (T)Activator.CreateInstance(implementation, args); instances.Add(instance); } } return(instances); }
/// <summary> /// Gets the implementations of the type specified by the type parameter. /// </summary> /// <typeparam name="T">The type parameter to find implementations of.</typeparam> /// <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>(bool useCaching = false) { return(ExtensionManager.GetImplementations <T>(null, useCaching)); }
/// <summary> /// Gets the first implementation of the type specified by the type parameter and located in the assemblies /// filtered by the predicate, or null if no implementations found. /// </summary> /// <typeparam name="T">The type parameter to find implementation 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>The first found implementation of the given type.</returns> public static Type GetImplementation <T>(Func <Assembly, bool> predicate, bool useCaching = false) { return(ExtensionManager.GetImplementations <T>(predicate, useCaching).FirstOrDefault()); }
public static IEnumerable <Type> GetImplementations <T>() { return(ExtensionManager.GetImplementations <T>(null)); }