public CommonTaskHolder FindTask(string key) { var assemblies = AssemblyLoadContext.Default.Assemblies; foreach (var assembly in assemblies) { foreach (var type in UtilReflection.GetImplementers <CommonTask>(assembly)) { var attr = UtilReflection.GetAttribute <DescriptorAttribute>(type); if (attr == null) { continue; } if (attr.Key != key) { continue; } var holder = CreateHolder(type, attr); return(holder); } } return(null); }
private CommonTaskHolder CreateHolder(Type taskType, DescriptorAttribute descriptor) { var key = taskType.Name; var name = taskType.FullName; if (descriptor == null) { descriptor = UtilReflection.GetAttribute <DescriptorAttribute>(taskType); if (descriptor != null) { key = descriptor.Key; name = descriptor.Name; } } var task = (CommonTask)_serviceLocator.GetService(taskType); return(new CommonTaskHolder { Key = key, Name = name, TaskType = taskType, Task = task }); }
public static CatalogType GetCatalogTypeFromAttribute <T>() { var type = typeof(T); var attr = UtilReflection.GetAttribute <CatalogTypeAttribute>(type); if (attr == null) { throw new InvalidOperationException("Catalog object without CatalogTypeAttribute: " + type.FullName); } return(attr.CatalogType); }
public void Find() { var assemblies = AssemblyLoadContext.Default.Assemblies; AssemblyLoadContext.Default.Resolving += Default_Resolving; TypeListContainers = new List <Type>(); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var type in types) { if (typeof(ITypeListContainer).IsAssignableFrom(type)) { TypeListContainers.Add(type); } var serviceAttribute = UtilReflection.GetAttribute <ServiceAttribute>(type); if (serviceAttribute != null) { RegisterService(type, serviceAttribute); continue; } var interfaceImplementationDefaultAttribute = UtilReflection.GetAttribute <InterfaceImplementationDefaultAttribute>(type); if (interfaceImplementationDefaultAttribute != null) { RegisterDefaultService(type, interfaceImplementationDefaultAttribute); continue; } var interfaceImplementationByConfigAttribute = UtilReflection.GetAttribute <InterfaceImplementationByConfigAttribute>(type); if (interfaceImplementationByConfigAttribute != null) { RegisterServiceByConfig(type, types.ToList(), interfaceImplementationByConfigAttribute); } } } }