/// <summary> /// Will create for you the needed instances of the given type children types /// with DEFAULT CONSTRUCTORS only, no params. /// </summary> static public List <TypeRequired> GetTypeChildrenInstances <TypeRequired>(IEnumerable <Assembly> assemblies) { List <TypeRequired> resultingInstances = new List <TypeRequired>(); foreach (Assembly assembly in assemblies) { // Collect all the types that match the description List <Type> blockTypes = ReflectionHelper.GetTypeChildrenTypes(typeof(TypeRequired), assembly); foreach (Type blockType in blockTypes) { System.Reflection.ConstructorInfo[] constructorInfo = blockType.GetConstructors(); if (constructorInfo == null || constructorInfo.Length == 0 || blockType.IsAbstract || blockType.IsClass == false) { continue; } resultingInstances.Add((TypeRequired)constructorInfo[0].Invoke(null)); } } return(resultingInstances); }
/// <summary> /// This will look for children types in Entry, Current, Executing, Calling assemly, /// as well as assemblies with names specified and found in the directory of the current application. /// </summary> /// <returns></returns> static public List <Type> GatherTypeChildrenTypesFromAssemblies(Type parentType, IEnumerable <Assembly> assemblies, bool allowOnlyClasses, bool allowAbstracts) { List <Type> resultingTypes = new List <Type>(); if (assemblies == null) { return(resultingTypes); } foreach (Assembly assembly in assemblies) { List <Type> types = ReflectionHelper.GetTypeChildrenTypes(parentType, assembly); foreach (Type type in types) { if ((allowOnlyClasses == false || type.IsClass) && (allowAbstracts || type.IsAbstract == false)) { resultingTypes.Add(type); } } } return(resultingTypes); }