Esempio n. 1
0
 public ServiceRegistryContainerRegistrationResult(string name, CoreServices.ServiceRegistry registry, Type type, MethodInfo method, ServiceRegistryLoaderAttribute attr)
 {
     Success         = true;
     Type            = type;
     MethodInfo      = method;
     Attribute       = attr;
     ServiceRegistry = registry;
     Name            = name;
 }
        private void Initialize(Type type, string name = null, string description = null)
        {
            LoaderType     = type.FullName;
            LoaderAssembly = type.Assembly.FullName;
            MethodInfo loaderMethodInfo = type.GetMethods().Where(mi => mi.HasCustomAttributeOfType(out ServiceRegistryLoaderAttribute a) && a.RegistryName.Equals(name)).FirstOrDefault();

            if (loaderMethodInfo == null)
            {
                loaderMethodInfo = type.GetFirstMethodWithAttributeOfType <ServiceRegistryLoaderAttribute>();
                if (loaderMethodInfo == null)
                {
                    throw new InvalidOperationException($"The specified type doesn't have a method addorned with an attribute of {nameof(ServiceRegistryLoaderAttribute)}");
                }
            }
            ServiceRegistryLoaderAttribute attr = loaderMethodInfo.GetCustomAttributeOfType <ServiceRegistryLoaderAttribute>();

            Name        = string.IsNullOrEmpty(name) ? (string.IsNullOrEmpty(attr.RegistryName) ?  $"{type.Assembly.GetFileInfo().Name}_{type.Name}" : attr.RegistryName): name;
            Description = string.IsNullOrEmpty(description) ? attr.Description: description;
        }