private void GetConcreteTypes(Assembly assembly, List <T> results) { if (ReflectionBlackList.IsBlackListed(assembly)) { return; } var allTypes = AssemblyTypesResolver.ResolveTypes(assembly, Logger); var concreteTypes = allTypes.Where(type => typeof(T).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract && !IgnoredTypes.Contains(type)); foreach (var type in concreteTypes) { try { var instance = (T)Activator.CreateInstance(type); results.Add(instance); } catch (Exception exception) { Logger.Error(Resources.DiscoverCreateInstance, exception, typeof(T), type); } } }
/// <summary> /// Executes the task. Returns continuation of the next task(s) in the chain. /// </summary> /// <returns></returns> public override TaskContinuation Execute() { Func <Type, bool> filter = type => KnownTypes.ActionInvokerType.IsAssignableFrom(type) && !IgnoredTypes.Contains(type); Container.GetService <IBuildManager>() .ConcreteTypes .Where(filter) .Each(type => Container.RegisterAsTransient(type)); return(TaskContinuation.Continue); }
/// <summary> /// Executes the task. Returns continuation of the next task(s) in the chain. /// </summary> /// <returns></returns> public override TaskContinuation Execute() { Func <Type, bool> filter = type => KnownTypes.ViewEngineType.IsAssignableFrom(type) && type.Assembly != KnownAssembly.AspNetMvcAssembly && !IgnoredTypes.Contains(type); Container.GetService <IBuildManager>() .ConcreteTypes .Where(filter) .Each(type => Container.RegisterAsSingleton(KnownTypes.ViewEngineType, type)); return(TaskContinuation.Continue); }
/// <summary> /// Executes the task. Returns continuation of the next task(s) in the chain. /// </summary> /// <returns></returns> public override TaskContinuation Execute() { Func <Type, bool> filter = type => KnownTypes.ControllerType.IsAssignableFrom(type) && type.Assembly != KnownAssembly.AspNetMvcAssembly && !type.Assembly.GetName().Name.Equals(KnownAssembly.AspNetMvcFutureAssemblyName, StringComparison.OrdinalIgnoreCase) && !IgnoredTypes.Contains(type); Container.GetService <IBuildManager>() .ConcreteTypes .Where(filter) .Each(type => Container.RegisterAsTransient(type)); return(TaskContinuation.Continue); }
private void GetConcreteTypes(Assembly assembly, List <T> results) { // GetTypes potentially throws and exception. Defensive coding as per http://haacked.com/archive/2012/07/23/get-all-types-in-an-assembly.aspx Type[] allTypes; try { allTypes = assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { allTypes = ex.Types.Where(t => t != null).ToArray(); foreach (var exception in ex.LoaderExceptions) { Logger.Warn(Resources.DiscoverGetType, exception); } } var concreteTypes = allTypes.Where(type => typeof(T).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract && !IgnoredTypes.Contains(type)); foreach (var type in concreteTypes) { try { var instance = (T)Activator.CreateInstance(type); results.Add(instance); } catch (Exception exception) { Logger.Error(Resources.DiscoverCreateInstance, exception, typeof(T), type); } } }
/// <summary> /// Discovers this all instanced of <typeparamref name="T"/> within the discovery location. /// </summary> public void Discover() { Logger.Debug("Discovering {0}'s in '{1}' and all sub directories.", typeof(T).Name, DiscoveryLocation); var results = new List <T>(); foreach (var file in Directory.GetFiles(DiscoveryLocation, "*.dll", SearchOption.AllDirectories)) { try { Assembly assembly = Assembly.LoadFrom(file); Type[] allTypes; // GetTypes potentially throws and exception. Defensive coding as per http://haacked.com/archive/2012/07/23/get-all-types-in-an-assembly.aspx try { allTypes = assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { allTypes = ex.Types.Where(t => t != null).ToArray(); foreach (var exception in ex.LoaderExceptions) { Logger.Warn(Resources.DiscoverGetType, exception); } } var concreteTypes = allTypes.Where(type => typeof(T).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract && !IgnoredTypes.Contains(type)); foreach (var type in concreteTypes) { try { var instance = (T)Activator.CreateInstance(type); results.Add(instance); } catch (Exception exception) { Logger.Error(Resources.DiscoverCreateInstance, exception, typeof(T), type); } } } catch (Exception exception) { Logger.Error(Resources.DiscoverLoadAssembly, exception, file); } } if (results.Count > 0) { Items.Clear(); foreach (var result in results) { Logger.Debug(string.Format(Resources.DiscoverableCollectionDiscover, typeof(T).Name, result.GetType())); } Items.AddRange(results); } }
public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration) { if (CurrentType != null) { NestedTypes = NestedTypes ?? new List <Tuple <TypeDeclaration, ITypeInfo> >(); NestedTypes.Add(new Tuple <TypeDeclaration, ITypeInfo>(typeDeclaration, CurrentType)); return; } ValidateNamespace(typeDeclaration); var rr = Resolver.ResolveNode(typeDeclaration); var fullName = rr.Type.ReflectionName; var partialType = Types.FirstOrDefault(t => t.Key == fullName); var add = true; var ignored = IgnoredTypes.Contains(fullName); var external = HasExternal(typeDeclaration); if (!external) { var resolveResult = Resolver.ResolveNode(typeDeclaration); if (resolveResult != null && resolveResult.Type != null) { var def = resolveResult.Type.GetDefinition(); external = def != null && (Validator.IsTypeFromH5Core(def.FullName) || def.ParentAssembly.AssemblyAttributes.Any(a => a.AttributeType.FullName == "H5.ExternalAttribute")); } } if ((external || ignored || IsNonScriptable(typeDeclaration)) && !IsObjectLiteral(typeDeclaration)) { if (partialType != null) { Types.Remove(partialType); } if (!ignored) { IgnoredTypes.Add(fullName); } return; } if (partialType == null) { ITypeInfo parentTypeInfo = null; var parentTypeDeclaration = typeDeclaration.GetParent <TypeDeclaration>(); if (parentTypeDeclaration != null) { var rr1 = Resolver.ResolveNode(parentTypeDeclaration); var parentName = rr1.Type.ReflectionName; parentTypeInfo = Types.FirstOrDefault(t => t.Key == parentName); } CurrentType = new TypeInfo() { Key = rr.Type.ReflectionName, TypeDeclaration = typeDeclaration, ParentType = parentTypeInfo, Name = typeDeclaration.Name, ClassType = typeDeclaration.ClassType, Namespace = Namespace, IsEnum = typeDeclaration.ClassType == ClassType.Enum, IsStatic = typeDeclaration.ClassType == ClassType.Enum || typeDeclaration.HasModifier(Modifiers.Static), IsObjectLiteral = IsObjectLiteral(typeDeclaration), Type = rr.Type }; } else { CurrentType = partialType; CurrentType.PartialTypeDeclarations.Add(typeDeclaration); add = false; } if (typeDeclaration.ClassType != ClassType.Interface) { typeDeclaration.AcceptChildren(this); } else { typeDeclaration.AcceptChildren(this); } if (add) { Types.Add(CurrentType); } if (typeDeclaration.ClassType != ClassType.Interface) { AddMissingAliases(typeDeclaration); } CurrentType = null; while (NestedTypes != null && NestedTypes.Count > 0) { var types = NestedTypes; NestedTypes = null; foreach (var nestedType in types) { VisitTypeDeclaration(nestedType.Item1); } } }