/// <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 = "TValue" > Option value type</typeparam> /// <typeparam name = "TValueCollection" > Value 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" > Options provider</param> /// <returns>ConfigurationPropertyWithOptionBuilder for selected property</returns> public static ConfigurationPropertyWithOptionValueBuilder PropertyWithMultipleOptionValues <TModel, TOption, TValue, TValueCollection, TConfigurationSet>(this IModelWithProperties <TModel> source, Expression <Func <TModel, TValueCollection> > expression, IConfigurationSetOptionValueProvider <TConfigurationSet, TOption, TValue> optionProvider) where TConfigurationSet : ConfigurationSet where TOption : new() where TValueCollection : ICollection <TValue> { var propertyName = ExpressionHelper.GetPropertyNameFromExpression(expression); var model = new ConfigurationPropertyWithMultipleOptionValuesModelDefinition <TConfigurationSet, TOption, TValue, TValueCollection>(optionProvider, propertyName, typeof(TModel)); source.ConfigurationProperties[propertyName] = model; return(new ConfigurationPropertyWithOptionValueBuilder(model)); }
private static ConfigurationPropertyWithMultipleOptionValuesModelDefinition BuildCollectionOptionValueModel(IConfigurationSetOptionValueProvider optionProvider, PropertyInfo property, Type parentType) { var definitionType = ReflectionHelpers.BuildGenericType(typeof(ConfigurationPropertyWithMultipleOptionValuesModelDefinition <, , ,>), optionProvider.ConfigurationSetType, optionProvider.OptionType, optionProvider.OptionValueType, property.PropertyType); var constructor = definitionType.GetConstructors().Single(); var propertyModel = (ConfigurationPropertyWithMultipleOptionValuesModelDefinition)constructor.Invoke(new object[] { optionProvider, property.Name, parentType }); return(propertyModel); }
public ConfigurationPropertyWithMultipleOptionValuesModelDefinition(IConfigurationSetOptionValueProvider <TConfigurationSet, TOption, TValue> optionProvider, string propertyName, Type propertyParentType) : base(propertyName, typeof(TConfigurationSet), typeof(TValue), propertyParentType) { this.optionProvider = optionProvider; dependency = new[] { new ConfigurationDependency(typeof(TConfigurationSet), optionProvider.OptionPropertyName) }; }