protected override void LoadFromPropertiesInternal(ComponentProcessorProperties properties, TypeAliasResolver typeAliasResolver, string procesorName) { if (properties.ContainsProperty(nameof(CodeProvider))) { var odeProviderAlias = properties.GetProperty(nameof(CodeProvider)); var codeProviderType = typeAliasResolver.ResolveType(odeProviderAlias); CodeProvider = (CodeProvider <MethodCodeInjectingCodeProviderArgument>)Activator.CreateInstance(codeProviderType); } else { CodeProvider = GetDefaultCodeProvider(); } }
protected override void LoadFromPropertiesInternal([NotNull] ComponentProcessorProperties properties, TypeAliasResolver typeAliasResolver, string processorName) { if (properties.ContainsProperty(nameof(CustomAttributeProvider))) { var customAttributeProviderAlias = properties.GetProperty(nameof(CustomAttributeProvider)); var customAttributeProviderType = typeAliasResolver.ResolveType(customAttributeProviderAlias); CustomAttributeProvider = (AttributeProvider)Activator.CreateInstance(customAttributeProviderType); } else { CustomAttributeProvider = GetDefaultCodeProvider(); } }
protected override void LoadFromPropertiesInternal(ComponentProcessorProperties properties, TypeAliasResolver typeAliasResolver, string procesorName) { if (properties.ContainsProperty(nameof(CustomValueHandlingCodeProvider))) { var customValueHandlingCodeProviderAlias = properties.GetProperty(nameof(CustomValueHandlingCodeProvider)); var customValueHandlingCodeProviderType = typeAliasResolver.ResolveType(customValueHandlingCodeProviderAlias); CustomValueHandlingCodeProvider = (CodeProvider <ParameterValueHandlingCodeProviderArgument>)Activator.CreateInstance(customValueHandlingCodeProviderType); } else { CustomValueHandlingCodeProvider = GetDefaultCodeProvider(); } properties.TryGetProperty(nameof(StateInstanceName), out stateInstanceName); }
private static IEnumerable <IComponentProcessor <ComponentProcessorConfiguration> > LoadProcessors( ProcessorDefinition[] processorDefinitions, ILogger logger, Dictionary <string, LazyAssembly> assembliesDict, TypeAliasResolver typeAliasResolver) { foreach (var processorDefinition in processorDefinitions) { logger.Notice($"Loading processor {processorDefinition.ProcessorName}."); var assembly = assembliesDict[processorDefinition.AssemblyAlias].Assembly.Value; var processorType = assembly.GetType(processorDefinition.ProcessorName); if (processorType == null) { throw new InvalidOperationException($"Unable to load '{processorDefinition.ProcessorName}' processor from assembly '{assembly.FullName}'. Cannot find specified type in assembly."); } var processorTypeGenericArgs = processorType.GetGenericArguments(); int numberOfProcessorGenericParameters = processorTypeGenericArgs.Where(arg => arg.IsGenericParameter).Count(); if (numberOfProcessorGenericParameters != processorDefinition.GenericArguments.Length) { throw new InvalidOperationException($"Unable to load '{processorDefinition.ProcessorName}' processor from assembly '{assembly.FullName}'. Number of generic parameters (={numberOfProcessorGenericParameters}) is different from number of configured processor generic arguments (={processorDefinition.GenericArguments.Length})."); } if (numberOfProcessorGenericParameters > 0) { var genericArgumentTypes = processorDefinition.GenericArguments.Select(arg => typeAliasResolver.ResolveType(arg)).ToArray(); processorType = processorType.MakeGenericType(genericArgumentTypes); } var processorProperties = new ComponentProcessorProperties(processorDefinition.Properties.Select(p => Tuple.Create(p.Name, p.Value))); var processorBaseGenericInterface = processorType.GetInterfaces().FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IComponentProcessor <>)); if (processorBaseGenericInterface == null) { throw new InvalidOperationException($"Unable to load '{processorDefinition.ProcessorName}' processor from assembly '{assembly.FullName}' because it does not implement {typeof(IComponentProcessor<>).FullName} interface."); } var processorConfigurationType = processorBaseGenericInterface.GenericTypeArguments[0]; var processorConfiguration = (ComponentProcessorConfiguration)Activator.CreateInstance(processorConfigurationType); processorConfiguration.LoadFromProperties(processorProperties, typeAliasResolver, processorDefinition.ProcessorName); var processor = (IComponentProcessor <ComponentProcessorConfiguration>)Activator.CreateInstance(processorType, processorConfiguration, logger); yield return(processor); } }