protected sealed override IEnumerator <IDiagnosticContext> GetEnumeratorCore(IDiagnosticContextFactory factory) { if (assembly == null || Ignore(assembly)) { yield break; } yield return(factory.Create(assembly)); var assemblyTypes = new AssemblyTypes(assembly, IncludeAllTypes(assembly)); foreach (var type in assemblyTypes) { if (type == null || Ignore(type)) { continue; } yield return(factory.Create(type)); var typeMembers = new TypeMembers(type, IncludeAllMembers(type)); foreach (var member in typeMembers) { if (member == null || Ignore(member)) { continue; } yield return(factory.Create(member)); } } }
/// <summary> /// Returns System.Type classes for all of the types found in the calling assembly. /// </summary> public static List <Type> GetTypesInAssembly(AssemblyTypes assemblyType) { var list = new List <Type>(); Assembly asm = null; switch (assemblyType) { case AssemblyTypes.CallingAssembly: asm = Assembly.GetCallingAssembly(); break; case AssemblyTypes.EntryAssembly: asm = Assembly.GetEntryAssembly(); break; case AssemblyTypes.ExecutingAssembly: asm = Assembly.GetExecutingAssembly(); break; } if (asm == null) { return(new List <Type>()); } foreach (var t in asm.GetTypes()) { list.Add(t); } return(list); }
public void successful_assembly_types() { var types = new AssemblyTypes(typeof(IContainer).Assembly); types.Record.Name.ShouldBe(typeof(IContainer).Assembly.FullName); types.Record.LoadException.ShouldBeNull(); }
public void successful_assembly_types() { var types = new AssemblyTypes(GetType().GetTypeInfo().Assembly); types.Record.Name.ShouldBe(GetType().GetTypeInfo().Assembly.FullName); ShouldBeNullExtensions.ShouldBeNull(types.Record.LoadException); }
static GamePacketMetadataMarker() { AssemblyTypes = typeof(GamePacketMetadataMarker) .Assembly .GetExportedTypes(); GamePacketPayloadTypes = AssemblyTypes .Where(t => typeof(GamePacketPayload).IsAssignableFrom(t)) .ToArray(); SerializableTypes = GamePacketPayloadTypes .Concat(AssemblyTypes.Where(t => t.GetCustomAttribute <WireDataContractAttribute>() != null)) .Distinct() .ToArray(); UnimplementedOperationCodes = new Lazy <IReadOnlyCollection <NetworkOperationCode> >(() => { var codes = GamePacketPayloadTypes .Where(t => t.GetCustomAttribute <GamePayloadOperationCodeAttribute>(true) != null) .Select(t => t.GetCustomAttribute <GamePayloadOperationCodeAttribute>(true).OperationCode) .Distinct() .ToArray(); return(((NetworkOperationCode[])Enum.GetValues(typeof(NetworkOperationCode))) .Where(o => !codes.Contains(o)) .ToArray()); }, true); }
public void failed_assembly_types() { var types = new AssemblyTypes("FakeOne", () => { throw new DivideByZeroException(); }); types.Record.Name.ShouldBe("FakeOne"); types.Record.LoadException.ShouldBeOfType <DivideByZeroException>(); }
/// <summary> /// 配置MVC插件程序集路由 /// </summary> /// <param name="mvcPlus"></param> public static void Config(Assembly mvcPlus, AssemblyTypes assType) { MVCPlusList.Add( new MVCPlusInfo() { PlusName = mvcPlus.GetName().Name, MvcPlusType = assType == AssemblyTypes.MVCHome ? MvcPlusTypes.MVCHome : MvcPlusTypes.MVC }); }
/// <summary> /// 配置MVC插件程序集路由 /// </summary> /// <param name="mvcPlus"></param> public static void Config(Assembly mvcPlus, AssemblyTypes assType) { MVCPlusList.Add( new MVCPlusInfo() { PlusName = mvcPlus.GetName().Name, MvcPlusType = assType == AssemblyTypes.MVCHome ? MvcPlusTypes.MVCHome : MvcPlusTypes.MVC }); }
static GamePacketStubMetadataMarker() { AssemblyTypes = typeof(GamePacketStubMetadataMarker) .Assembly .GetExportedTypes(); GamePacketPayloadStubTypes = AssemblyTypes .Where(t => typeof(GamePacketPayload).IsAssignableFrom(t)) .ToArray(); }
protected AssemblyTypes GetAssemblyTypes(AssemblyDefinition assembly) { AssemblyTypes assemblyTypes = AssemblyTypes.Unknown; if (assembly.Name.PublicKeyTokenAsString == "b77a5c561934e089" || assembly.Name.PublicKeyTokenAsString == "b03f5f7f11d50a3a" || assembly.Name.PublicKeyTokenAsString == "31bf3856ad364e35") { assemblyTypes |= AssemblyTypes.FrameworkAssembly; } foreach (AssemblyNameReference reference in assembly.MainModule.AssemblyReferences) { if (reference.Name == "PresentationFramework") { assemblyTypes |= AssemblyTypes.WPF; } else if (reference.Name == "System.Windows.Forms") { assemblyTypes |= AssemblyTypes.WinForms; } else if (reference.Name.StartsWith("Microsoft.AspNetCore")) { assemblyTypes |= AssemblyTypes.AspNetCore; } else if (reference.Name == "System.Runtime" && reference.Version == new Version(4, 2, 0, 0)) { assemblyTypes |= AssemblyTypes.NetCore; } else if (reference.Name == "System.Web.Mvc") { assemblyTypes |= AssemblyTypes.MVC; } else if (reference.Name == "Windows") { assemblyTypes |= AssemblyTypes.Windows8Application; } else if (reference.Name == "Windows.Foundation.UniversalApiContract") { assemblyTypes |= AssemblyTypes.UniversalWindows; } else if (reference.Name == "Mono.Android") { assemblyTypes |= AssemblyTypes.XamarinAndroid; } else if (reference.Name == "Xamarin.iOS" || reference.Name == "monotouch") { assemblyTypes |= AssemblyTypes.XamarinIOS; } } return(assemblyTypes); }
public Api(Assembly assembly = null) { Assembly = assembly ?? (typeof(object)).Assembly; AssemblyTypes = Assembly. GetTypes(). Where(t => !t.IsDefined(typeof(CompilerGeneratedAttribute), false)). OrderBy(t => t.Namespace). ThenBy(t => SortName(t)); AssemblyNamespaces = AssemblyTypes. GroupBy(t => t.Namespace). Select(g => g.First().Namespace). OrderBy(ns => ns); }
/// <summary> /// Programmatically directs Marten to map all the subclasses of <cref name="T" /> to a hierarchy of types. /// <c>Unadvised in projects with many types.</c> /// </summary> /// <returns></returns> public void AddHierarchy() { var baseType = _parent.DocumentType; var assembly = baseType.GetTypeInfo().Assembly; var types = new AssemblyTypes(assembly); var allSubclassTypes = types.ClosedTypes.Concretes .Where(x => x.CanBeCastTo(baseType) && x != baseType); foreach (var subclassType in allSubclassTypes) { Add(subclassType, null); } }
public void Execute() { var typeOfIHaveCustomMapping = typeof(IHaveCustomMapping); var typeOfIMapFrom = typeof(IMapFrom <>); // Type 符合 IHaveCustomMapping 和 IMapFrom 的 predicate方法 // 這個predicate 的條件和下面個別mapping的第一個條件是一致的。 Func <Type, bool> predicate = (t => typeOfIHaveCustomMapping.IsAssignableFrom(t) || // 找到符合IHaveCustomMapping t.GetInterfaces().Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeOfIMapFrom).Any()); // 找到符合IMapFrom<> var types = AssemblyTypes.GetAssemblyFromDirectory(assembly => assembly.GetExportedTypes().Where(predicate).Any()) // 選擇要讀進來的Assembly - 只有符合IHaveCustomMapping 和 IMapFrom才讀 // 把讀進來的Assembly取出裡面符合兩個interface的Type .SelectMany(x => x.GetExportedTypes() .Where(predicate)).ToList(); LoadStandardMappings(types); LoadCustomMappings(types); }
public static void Configure(ContainerBuilder builder, bool isProduction) { builder.RegisterSource(new ContravariantRegistrationSource()); var repositoryTypes = AssemblyTypes.Where(t => t.ImplementsInterface <IService>()).ToArray(); foreach (var repositoryType in repositoryTypes) { builder.RegisterType(repositoryType) .AsImplementedInterfaces() .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies) .WithParameter(new ResolvedParameter((p, ctx) => p.Name == "asNoTracking", (p, ctx) => false)) .InstancePerLifetimeScope(); } var eventHandlerTypes = AssemblyTypes.Where(t => t.Name.EndsWith("EventHandler")).ToArray(); foreach (var eventHandlerType in eventHandlerTypes) { builder.RegisterType(eventHandlerType) .AsImplementedInterfaces() .PropertiesAutowired() .WithParameter(AppConfigParameter) .InstancePerLifetimeScope(); } builder.RegisterType <EntityChangeEventPublisherEntityContextInterceptor>().PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies).InstancePerLifetimeScope(); builder.RegisterType <EntityContext>() .As <IEntityContext>() .PropertiesAutowired() .EnableInterfaceInterceptors() .InterceptedBy(typeof(EntityChangeEventPublisherEntityContextInterceptor)) .InstancePerLifetimeScope(); builder.RegisterType <UnitOfWork>().As <IUnitOfWork>().PropertiesAutowired().InstancePerLifetimeScope(); builder.RegisterType <EventPublisher>().As <IEventPublisher>().PropertiesAutowired().InstancePerLifetimeScope(); }
public void SetUp() { theInners = GetType().GetNestedTypes(); theTypes = new AssemblyTypes(theInners); }
/// <summary> /// Gets all types in the specified assembly (where not compiler generated) /// </summary> /// <param name="a">The assembly to check</param> /// <returns>All the types in the assembly</returns> public static IEnumerable <Type> GetAssemblyTypes(Assembly a) { Contract.Assert(a != null); if (!AssemblyTypes.TryGetValue(a.FullName, out AssemblyDefinition b)) { StaticLogger.Log($"RE: Getting types for assembly {a.FullName}", StaticLogger.LoggingLevel.Call); List <Type> types = null; try { types = a.GetTypes().Where(t => !Attribute.IsDefined(t, typeof(CompilerGeneratedAttribute), true)).Distinct().ToList(); } catch (ReflectionTypeLoadException ex) { StaticLogger.Log(ex.Message, StaticLogger.LoggingLevel.Call); StaticLogger.Log(ex.StackTrace, StaticLogger.LoggingLevel.Call); try { types = new List <Type>(); foreach (Type t in ex.Types) { try { if (t != null && !Attribute.IsDefined(t, typeof(CompilerGeneratedAttribute), true)) { types.Add(t); } } catch (Exception exxx) { StaticLogger.Log("RE: Failed to load type: " + exxx.Message, StaticLogger.LoggingLevel.Call); } } } catch (Exception exx) { StaticLogger.Log("RE: Failed to enumerate loaded types: " + exx.Message, StaticLogger.LoggingLevel.Call); } types = types.Distinct().ToList(); } catch (Exception ex) { StaticLogger.Log(ex.Message, StaticLogger.LoggingLevel.Call); StaticLogger.Log(ex.StackTrace, StaticLogger.LoggingLevel.Call); types = new List <Type>(); } if (StaticLogger.Level != StaticLogger.LoggingLevel.None) { foreach (Type t in types) { StaticLogger.Log($"RE: Found type {t.FullName}", StaticLogger.LoggingLevel.Call); } } AssemblyTypes.TryAdd(a.FullName, new AssemblyDefinition() { ContainingAssembly = a, LoadedTypes = types }); return(types.ToList()); } else { StaticLogger.Log($"RE: Using cached types for {a.FullName}", StaticLogger.LoggingLevel.Call); return(b.LoadedTypes); } }
public TypeRepositoryTester() { theInners = GetType().GetNestedTypes(BindingFlags.Public); theTypes = new AssemblyTypes("some name", () => theInners); }
/// <summary> /// Gets the currently loaded assembly in which the specified class is defined. /// </summary> public static Assembly GetAssembly(Type type) { return(AssemblyTypes.GetAssemblyFromType(type)); }
/// <summary> /// Gets the process executable. /// </summary> public static Assembly GetEntryAssembly() { return(AssemblyTypes.GetEntryAssembly()); }
public IEnumerable <Type> AssemblyNamespaceTypes(string ns) { return(AssemblyTypes. Where(t => ns == t.Namespace). OrderBy(t => SortName(t))); }
public void SetUp() { theInners = GetType().GetNestedTypes(); theTypes = new AssemblyTypes("some name", () => theInners); }
/// <summary> /// Return the Specified Type /// </summary> /// <param name="typeName">Name of the Type</param> /// <returns></returns> public Type GetTypeByName(string typeName) { return(AssemblyTypes.FirstOrDefault(fd => fd.Name == typeName)); }