private static ConfigurationPropertyModelBase BuildCollectionOptionModel(IConfigurationSetOptionProvider optionProvider, PropertyInfo property, Type parentType) { var definitionType = ReflectionHelpers.BuildGenericType(typeof(ConfigurationPropertyWithMultipleOptionsModelDefinition <, ,>), optionProvider.ConfigurationSetType, optionProvider.OptionType, property.PropertyType); var constructor = definitionType.GetConstructors().Single(); var propertyModel = (ConfigurationPropertyWithOptionModelDefinition)constructor.Invoke(new object[] { optionProvider, property.Name, parentType }); return(propertyModel); }
/// <summary> /// Gets ConfigurationPropertyModelBuilder for property with multiple option /// Overides existing configuration from property /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <typeparam name="TOption">Option type</typeparam> /// <typeparam name="TOptionCollection">Option Collection type</typeparam> /// <typeparam name="TConfigurationSet">ConfigurationSet to provide available options</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <param name="optionProvider">Option provider</param> /// <returns>ConfigurationPropertyWithOptionBuilder for selected property</returns> public static ConfigurationPropertyWithOptionBuilder PropertyWithMultipleOptions <TModel, TOption, TOptionCollection, TConfigurationSet>(this IModelWithProperties <TModel> source, Expression <Func <TModel, TOptionCollection> > expression, IConfigurationSetOptionProvider <TConfigurationSet, TOption> optionProvider) where TConfigurationSet : ConfigurationSet where TOption : new() where TOptionCollection : ICollection <TOption> { var propertyName = ExpressionHelper.GetPropertyNameFromExpression(expression); var model = new ConfigurationPropertyWithMultipleOptionsModelDefinition <TConfigurationSet, TOption, TOptionCollection>(optionProvider, propertyName, typeof(TModel)); source.ConfigurationProperties[propertyName] = model; return(new ConfigurationPropertyWithOptionBuilder(model)); }
public ConfigurationPropertyWithMultipleOptionsModelDefinition(IConfigurationSetOptionProvider <TConfigSet, TOption> optionProvider, string propertyName, Type propertyParentType) : base(propertyName, typeof(TConfigSet), typeof(TOption), propertyParentType) { this.optionProvider = optionProvider; dependency = new[] { new ConfigurationDependency(typeof(TConfigSet), optionProvider.OptionPropertyName) }; }