Beispiel #1
0
        public static T GetInstance <T>(Func <Assembly, bool> predicate)
        {
            IEnumerable <T> instances = ExtensionManager.GetInstances <T>(predicate);

            if (instances.Count() == 0)
            {
                throw new ArgumentException("Instance of " + typeof(T) + " can't be created");
            }

            return(instances.FirstOrDefault());
        }
 /// <summary>
 /// Gets the new instances 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>
 /// <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)
 {
     return(ExtensionManager.GetInstances <T>(predicate, useCaching, new object[] { }));
 }
 /// <summary>
 /// Gets the new instances (using constructor that matches the arguments) of the implementations
 /// of the type specified by the type parameter or empty enumeration if no implementations found.
 /// </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 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>(bool useCaching = false, params object[] args)
 {
     return(ExtensionManager.GetInstances <T>(null, useCaching, args));
 }
 /// <summary>
 /// Gets the new instances of the implementations of the type specified by the type parameter
 /// or empty enumeration if no implementations found.
 /// </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 instance(s) of the same type(s) is requested.
 /// </param>
 /// <returns>The instances of the found implementations of the given type.</returns>
 public static IEnumerable <T> GetInstances <T>(bool useCaching = false)
 {
     return(ExtensionManager.GetInstances <T>(null, useCaching, new object[] { }));
 }
 /// <summary>
 /// Gets the new instance (using constructor that matches the arguments) of 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 instance(s) of the same type(s) is requested.
 /// </param>
 /// <param name="args">The arguments to be passed to the constructor.</param>
 /// <returns>The instance of the first found implementation of the given type.</returns>
 public static T GetInstance <T>(Func <Assembly, bool> predicate, bool useCaching = false, params object[] args)
 {
     return(ExtensionManager.GetInstances <T>(predicate, useCaching, args).FirstOrDefault());
 }
Beispiel #6
0
 public static IEnumerable <T> GetInstances <T>()
 {
     return(ExtensionManager.GetInstances <T>(null));
 }
Beispiel #7
0
 public static T GetInstance <T>(Func <Assembly, bool> predicate)
 {
     return(ExtensionManager.GetInstances <T>(predicate).FirstOrDefault());
 }
Beispiel #8
0
 /// <summary>
 /// Gets the new instances (using constructor that matches the arguments) of the implementations
 /// of the type specified by the type parameter or empty enumeration if no implementations found.
 /// </summary>
 /// <typeparam name="T">The type parameter to find implementations of.</typeparam>
 /// <param name="args">The arguments to be passed to the constructors.</param>
 /// <returns></returns>
 public static IEnumerable <T> GetInstances <T>(params object[] args)
 {
     return(ExtensionManager.GetInstances <T>(null, args));
 }