/// <summary> /// Returns the constructors for implementations of a particular interface /// type. Constructor info is cached after the initial crawl. /// </summary> /// <typeparam name="TInterface"></typeparam> /// <returns></returns> private IEnumerable <ConstructorInfo> GetConstructors <TInterface>() { if (ConstructorCache.ContainsKey(typeof(TInterface))) { return(ConstructorCache[typeof(TInterface)]); } else { var constructors = new LinkedList <ConstructorInfo>(); foreach (var asm in Assemblies) { foreach (var type in asm.GetTypes()) { if (type.IsClass && !type.IsAbstract) { if (type.GetInterfaces().Contains(typeof(TInterface))) { var constructor = type.GetConstructor(Type.EmptyTypes); constructors.AddLast(constructor); } } } } ConstructorCache[typeof(TInterface)] = constructors; return(constructors); } }
/// <summary> /// Returns the constructors for implementations of a particular interface /// type. Constructor info is cached after the initial crawl. /// </summary> /// <typeparam name="TInterface"></typeparam> /// <returns></returns> private IEnumerable <ConstructorInfo> GetConstructors <TInterface>() { if (ConstructorCache.ContainsKey(typeof(TInterface))) { return(ConstructorCache[typeof(TInterface)]); } else { LinkedList <ConstructorInfo> constructors = new LinkedList <ConstructorInfo>(); foreach (Assembly asm in Assemblies) { foreach (Type type in asm.GetTypes()) { if (type.IsClass && !type.IsAbstract) { if (type.GetInterfaces().Contains(typeof(TInterface))) { if (constructorArgs == null) { ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes); constructors.AddLast(constructor); } else { Type[] types = new Type[constructorArgs.Length]; for (int i = 0; i < constructorArgs.Length; i++) { types[i] = constructorArgs[i].GetType(); } ConstructorInfo constructor = type.GetConstructor(types); constructors.AddLast(constructor); } } } } } ConstructorCache[typeof(TInterface)] = constructors; return(constructors); } }
/// <summary> /// Returns the constructors for implementations of a particular interface /// type. Constructor info is cached after the initial crawl. /// </summary> /// <typeparam name="TInterface"></typeparam> /// <returns></returns> private IEnumerable <ConstructorInfo> GetConstructors <TInterface>() { if (ConstructorCache.ContainsKey(typeof(TInterface))) { return(ConstructorCache[typeof(TInterface)]); } var constructors = new LinkedList <ConstructorInfo>(); foreach (ConstructorInfo constructor in Assemblies.SelectMany(asm => ( from type in asm.GetTypes() where type.IsClass && !type.IsAbstract && type.GetInterfaces().Contains(typeof(TInterface)) select type.GetConstructor(Type.EmptyTypes)))) { constructors.AddLast(constructor); } ConstructorCache[typeof(TInterface)] = constructors; return(constructors); }