private bool MayRunConfigurator(CachedType cachedType) { if (cachedType.State >= ProcessingState.ConfiguratorRan) { return(false); } if (cachedType.State != ProcessingState.Configured) { throw new InvalidOperationException($"The state of type '{cachedType.Type.Name}' must be" + $" '{ProcessingState.Configured}' but is '{cachedType.State}'."); } return(cachedType.RegistratorConfigurator != null); }
private bool MayConfigureType(CachedType cachedType) { if (cachedType.State >= ProcessingState.Configured) { return(false); } if (cachedType.State != ProcessingState.RegistratorRan) { throw new InvalidOperationException($"The state of type '{cachedType.Type.Name}' must be" + $" '{ProcessingState.Registered}' but is '{cachedType.State}'."); } // The conditions were already checked during registration. return(true); }
private bool MayCacheExtensionType(CachedType cachedType) { if (cachedType.State >= ProcessingState.CachedExtension) { return(false); } if (cachedType.State != ProcessingState.None) { throw new InvalidOperationException($"The state of type '{cachedType.Type.Name}' must be" + $" '{ProcessingState.None}' but is '{cachedType.State}'."); } var type = cachedType.Type; return(type.IsClass && !type.IsAbstract && typeof(IExtensionForProcessableAttribute).IsAssignableFrom(type)); }
private void RunConfigurator(IConfigurationContext context, CachedType cachedType) { if (!MayRunConfigurator(cachedType) || SimulateOnlyUnprocessableTypes) { if (cachedType.State == ProcessingState.Configured) { cachedType.State = ProcessingState.ConfiguratorRan; } return; } cachedType.RegistratorConfigurator !.Configure(context); cachedType.State = ProcessingState.ConfiguratorRan; Options.Logger?.Log($"Ran configurator '{cachedType.Type.Name}'"); }
private bool MayRunRegistrator(CachedType cachedType) { if (cachedType.State >= ProcessingState.RegistratorRan) { return(false); } if (cachedType.State != ProcessingState.Registered) { throw new InvalidOperationException($"The state of type '{cachedType.Type.Name}' must be" + $" '{ProcessingState.Registered}' but is '{cachedType.State}'."); } var type = cachedType.Type; return(type.IsClass && !type.IsAbstract && typeof(IRegistratorConfigurator).IsAssignableFrom(type) && type != typeof(IRegistratorConfigurator)); }
private bool MayRegisterType(CachedType cachedType) { if (cachedType.State >= ProcessingState.Registered) { return(false); } if (cachedType.State != ProcessingState.CachedExtension) { throw new InvalidOperationException($"The state of type '{cachedType.Type.Name}' must be" + $" '{ProcessingState.CachedExtension}' but is '{cachedType.State}'."); } var type = cachedType.Type; return(type.IsClass && !type.IsAbstract && (!Options.ProcessOnlyClassesDerivedFromIProcessable || typeof(IProcessable).IsAssignableFrom(type))); }
private void CacheTypes(CachedAssembly cachedAssembly) { if (cachedAssembly.TypesAndExtensionsAreCached) { return; } foreach (var type in cachedAssembly.Assembly.GetExportedTypes()) { if (Options.ExcludedTypes.Contains(type)) { Options.Logger?.Log($"Type '{type.Name}' is excluded from processing."); } else { var cachedType = new CachedType(type); CachedTypes.Add(cachedType.Type, cachedType); Statistics.CachedTypes++; } } }