/// <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 Selector</param> /// <param name = "keySelector" > Option value selector</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, Expression <Func <TConfigurationSet, OptionSet <TOption> > > optionProvider, Expression <Func <TOption, TValue> > keySelector) where TConfigurationSet : ConfigurationSet where TOption : new() where TValueCollection : ICollection <TValue> { var optionValueProvider = ConfigurationSetOptionProvider.Create(optionProvider, keySelector.Compile()); return(source.PropertyWithMultipleOptionValues(expression, optionValueProvider)); }
/// <summary> /// Gets ConfigurationCollectionPropertyBuilder for a collection /// </summary> /// <typeparam name="TModel">Property parent Type</typeparam> /// <param name="source">model with property</param> /// <param name="expression">collection selector</param> /// <returns>ConfigurationCollectionPropertyBuilder for selected property</returns> public static ConfigurationStringCollectionPropertyBuilder Collection <TModel>(this IModelWithProperties <TModel> source, Expression <Func <TModel, ICollection <string> > > expression) => source.StringPrimitiveCollection(expression);
/// <summary> /// Gets ConfigurationPropertyModelBuilder for float value /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <returns>ConfigurationFloatPropertyBuilder for selected property</returns> public static ConfigurationFloatPropertyBuilder <decimal> Property <TModel>(this IModelWithProperties <TModel> source, Expression <Func <TModel, decimal> > expression) => source.CreateForFloat <TModel, decimal>(expression);
private static ConfigurationIntegerPropertyBuilder <TProperty> CreateForNullableInterger <TModel, TProperty>(this IModelWithProperties <TModel> source, LambdaExpression expression) where TProperty : struct, IComparable { return(new ConfigurationIntegerPropertyBuilder <TProperty>(source.GetOrAddPrimitivePropertyDefinition(expression, typeof(TProperty?), false))); }
/// <summary> /// Gets ConfigurationPropertyModelBuilder for integer value /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <returns>ConfigurationIntegerPropertyBuilder for selected property</returns> public static ConfigurationIntegerPropertyBuilder <ulong> Property <TModel>(this IModelWithProperties <TModel> source, Expression <Func <TModel, ulong> > expression) => source.CreateForInterger <TModel, ulong>(expression);
/// <summary> /// Gets ConfigurationCollectionPropertyBuilder for a collection /// </summary> /// <typeparam name="TModel">Property parent Type</typeparam> /// <typeparam name="TConfig">Type of object in collection</typeparam> /// <param name="source">model with property</param> /// <param name="expression">collection selector</param> /// <returns>ConfigurationCollectionPropertyBuilder for selected property</returns> public static ConfigurationCollectionPropertyBuilder <TConfig> Collection <TModel, TConfig>(this IModelWithProperties <TModel> source, Expression <Func <TModel, ICollection <TConfig> > > expression) where TConfig : new() { var body = GetExpressionBody(expression); ConfigurationPropertyModelBase value; if (!source.ConfigurationProperties.TryGetValue(body.Member.Name, out value) || !(value is ConfigurationCollectionPropertyDefinition <TConfig>)) { var type = body.Type; if (type == typeof(ICollection <TConfig>)) { type = typeof(List <TConfig>); } var definition = new ConfigurationCollectionPropertyDefinition <TConfig>(body.Member.Name, typeof(TConfig), typeof(TModel), type); ApplyDefaultPropertyDefinitions(definition); value = definition; source.ConfigurationProperties[value.ConfigurationPropertyName] = value; } var builder = new ConfigurationCollectionPropertyBuilder <TConfig>((ConfigurationCollectionPropertyDefinition)value); return(builder); }
/// <summary> /// Gets ConfigurationPropertyModelBuilder for Class value /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <typeparam name="TClass">Class model type</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <returns>ConfigurationBoolPropertyBuilder for selected property</returns> public static ConfigurationClassPropertyBuilder <TClass> Property <TModel, TClass>(this IModelWithProperties <TModel> source, Expression <Func <TModel, TClass> > expression) where TClass : new() => new ConfigurationClassPropertyBuilder <TClass>(source.GetOrAddClassPropertyDefinition <TModel, TClass>(expression));
private static ConfigurationPropertyWithOptionBuilder PropertyWithMultipleOptionsInternal <TModel, TOption, TOptionCollection, TOptionProvider>(this IModelWithProperties <TModel> source, Expression <Func <TModel, TOptionCollection> > expression, Func <TOptionProvider, IEnumerable <TOption> > optionProvider, Func <TOption, string> keySelector, Func <TOption, string> displaySelector) where TOptionCollection : ICollection <TOption> where TOptionProvider : class where TOption : new() { var body = GetExpressionBody(expression); var model = new ConfigurationPropertyWithMultipleOptionsModelDefinition <TOptionCollection, TOption, TOptionProvider>(optionProvider, keySelector, displaySelector, body.Member.Name, typeof(TModel)); source.ConfigurationProperties[body.Member.Name] = model; return(new ConfigurationPropertyWithOptionBuilder(model)); }
/// <summary> /// Gets ConfigurationPropertyModelBuilder for property with option /// Overides existing configuration from property /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <typeparam name="TOption">Option type</typeparam> /// <typeparam name="TOptionProvider">Class used to provide available options</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <param name="optionProvider">Function that provides the available options</param> /// <param name="keySelector">Selector for the option key</param> /// <param name="displaySelector">Selector for the option display value</param> /// <returns>ConfigurationPropertyWithOptionBuilder for selected property</returns> public static ConfigurationPropertyWithOptionBuilder PropertyWithOptions <TModel, TOption, TOptionProvider>(this IModelWithProperties <TModel> source, Expression <Func <TModel, TOption> > expression, Func <TOptionProvider, IEnumerable <TOption> > optionProvider, Func <TOption, string> keySelector, Func <TOption, string> displaySelector) where TOptionProvider : class { var body = GetExpressionBody(expression); return(source.PropertyWithOptionsInternal(body, optionProvider, keySelector, displaySelector)); }
/// <summary> /// Gets ConfigurationPropertyModelBuilder for property with option /// Overides existing configuration from property /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <typeparam name="TOption">Option type</typeparam> /// <typeparam name="TConfigurationSet">ConfigurationSet to provide available options</typeparam> /// <typeparam name="TValue">Property Type</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <param name="optionProvider">Options Selector</param> /// <param name="keySelector">Value Selector</param> /// <returns>ConfigurationPropertyWithOptionBuilder for selected property</returns> public static ConfigurationPropertyWithOptionValueBuilder PropertyWithOptionValue <TModel, TValue, TOption, TConfigurationSet>(this IModelWithProperties <TModel> source, Expression <Func <TModel, TValue> > expression, Expression <Func <TConfigurationSet, OptionSet <TOption> > > optionProvider, Expression <Func <TOption, TValue> > keySelector) where TConfigurationSet : ConfigurationSet { var propertyName = ExpressionHelper.GetPropertyNameFromExpression(expression); var optionName = ExpressionHelper.GetPropertyNameFromExpression(optionProvider); var model = new ConfigurationPropertyWithOptionValueModelDefinition <TConfigurationSet, TOption, TValue>(optionProvider.Compile(), keySelector.Compile(), optionName, propertyName, typeof(TModel)); source.ConfigurationProperties[propertyName] = model; return(new ConfigurationPropertyWithOptionValueBuilder(model)); }
private static ConfigurationPropertyWithOptionBuilder PropertyWithOptionsInternal <TModel, TOption>(this IModelWithProperties <TModel> source, MemberExpression expression, Func <IEnumerable <TOption> > optionProvider, Func <TOption, string> keySelector, Func <TOption, string> displaySelector) { var model = new ConfigurationPropertyWithOptionsModelDefinition <TOption>(optionProvider, keySelector, displaySelector, expression.Member.Name, typeof(TModel)); source.ConfigurationProperties[expression.Member.Name] = model; return(new ConfigurationPropertyWithOptionBuilder(model)); }
/// <summary> /// Gets ConfigurationPropertyModelBuilder for a nullable date time value /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <returns>ConfigurationDateTimePropertyBuilder for selected property</returns> public static ConfigurationDateTimePropertyBuilder Property <TModel>(this IModelWithProperties <TModel> source, Expression <Func <TModel, DateTime?> > expression) => new ConfigurationDateTimePropertyBuilder(source.GetOrAddPrimitivePropertyDefinition(expression, typeof(DateTime?), false));
/// <summary> /// Gets ConfigurationPropertyModelBuilder for float value /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <returns>ConfigurationFloatPropertyBuilder for selected property</returns> public static ConfigurationFloatPropertyBuilder <double> Property <TModel>(this IModelWithProperties <TModel> source, Expression <Func <TModel, double?> > expression) => source.CreateForNullableFloat <TModel, double>(expression);
private static ConfigurationIntegerCollectionPropertyBuilder <TConfig> IntegerPrimitiveCollection <TModel, TConfig>(this IModelWithProperties <TModel> source, Expression <Func <TModel, ICollection <TConfig> > > expression) where TConfig : IComparable { var body = ExpressionHelper.GetExpressionBody(expression); ConfigurationPropertyModelBase value; if (!source.ConfigurationProperties.TryGetValue(body.Member.Name, out value) || !(value is ConfigurationPrimitiveCollectionPropertyDefinition)) { var type = body.Type; if (type == typeof(ICollection <TConfig>)) { type = typeof(List <TConfig>); } var definition = new ConfigurationPrimitiveCollectionPropertyDefinition <TConfig>(body.Member.Name, typeof(TConfig), typeof(TModel), type); value = definition; source.ConfigurationProperties[value.ConfigurationPropertyName] = value; } var builder = new ConfigurationIntegerCollectionPropertyBuilder <TConfig>((ConfigurationPrimitiveCollectionPropertyDefinition)value); return(builder); }
/// <summary> /// Gets ConfigurationPropertyModelBuilder for property with option /// Overides existing configuration from property /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <typeparam name="TOption">Option 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 PropertyWithOption <TModel, TOption, TConfigurationSet>(this IModelWithProperties <TModel> source, Expression <Func <TModel, TOption> > expression, IConfigurationSetOptionProvider <TConfigurationSet, TOption> optionProvider) where TConfigurationSet : ConfigurationSet { var propertyName = ExpressionHelper.GetPropertyNameFromExpression(expression); var model = new ConfigurationPropertyWithOptionModelDefinition <TConfigurationSet, TOption>(optionProvider, propertyName, typeof(TModel)); source.ConfigurationProperties[propertyName] = model; return(new ConfigurationPropertyWithOptionBuilder(model)); }
/// <summary> /// Gets ConfigurationPropertyModelBuilder for property with option /// Overides existing configuration from property /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <typeparam name="TOption">Option type</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <param name="optionProvider">Function that provides the available options</param> /// <param name="keySelector">Selector for the option key</param> /// <param name="displaySelector">Selector for the option display value</param> /// <returns>ConfigurationPropertyWithOptionBuilder for selected property</returns> public static ConfigurationPropertyWithOptionBuilder PropertyWithOptions <TModel, TOption>(this IModelWithProperties <TModel> source, Expression <Func <TModel, TOption> > expression, Func <IEnumerable <TOption> > optionProvider, Func <TOption, int> keySelector, Func <TOption, string> displaySelector) { return(source.PropertyWithOptions(expression, optionProvider, option => keySelector(option).ToString(), displaySelector)); }
/// <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">Options Selector</param> /// <returns>ConfigurationPropertyWithOptionBuilder for selected property</returns> public static ConfigurationPropertyWithOptionBuilder PropertyWithMultipleOptions <TModel, TOption, TOptionCollection, TConfigurationSet>(this IModelWithProperties <TModel> source, Expression <Func <TModel, TOptionCollection> > expression, Expression <Func <TConfigurationSet, OptionSet <TOption> > > optionProvider) where TConfigurationSet : ConfigurationSet where TOption : new() where TOptionCollection : ICollection <TOption> { return(source.PropertyWithMultipleOptions(expression, ConfigurationSetOptionProvider.Create(optionProvider))); }
/// <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="TOptionProvider">Class used to provide available options</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <param name="optionProvider">Function that provides the available options</param> /// <param name="keySelector">Selector for the option key</param> /// <param name="displaySelector">Selector for the option display value</param> /// <returns>ConfigurationPropertyWithOptionBuilder for selected property</returns> public static ConfigurationPropertyWithOptionBuilder PropertyWithMulitpleOptions <TModel, TOption, TOptionProvider>(this IModelWithProperties <TModel> source, Expression <Func <TModel, ICollection <TOption> > > expression, Func <TOptionProvider, IEnumerable <TOption> > optionProvider, Func <TOption, string> keySelector, Func <TOption, string> displaySelector) where TOptionProvider : class where TOption : new() { return(source.PropertyWithMultipleOptionsInternal(expression, optionProvider, option => keySelector(option), displaySelector)); }
/// <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">Options Selector</param> /// <returns>ConfigurationPropertyWithOptionBuilder for selected property</returns> public static ConfigurationPropertyWithOptionBuilder PropertyWithMultipleOptions <TModel, TOption, TOptionCollection, TConfigurationSet>(this IModelWithProperties <TModel> source, Expression <Func <TModel, TOptionCollection> > expression, Expression <Func <TConfigurationSet, OptionSet <TOption> > > optionProvider) where TConfigurationSet : ConfigurationSet where TOption : new() where TOptionCollection : ICollection <TOption> { var propertyName = ExpressionHelper.GetPropertyNameFromExpression(expression); var optionName = ExpressionHelper.GetPropertyNameFromExpression(optionProvider); var model = new ConfigurationPropertyWithMultipleOptionsModelDefinition <TConfigurationSet, TOption, TOptionCollection>(optionProvider.Compile(), optionName, propertyName, typeof(TModel)); source.ConfigurationProperties[propertyName] = model; return(new ConfigurationPropertyWithOptionBuilder(model)); }
/// <summary> /// Gets ConfigurationPropertyModelBuilder for enum value /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <returns>ConfigurationEnumPropertyBuilder for selected property</returns> public static ConfigurationEnumPropertyBuilder Property <TModel>(this IModelWithProperties <TModel> source, Expression <Func <TModel, Enum> > expression) => new ConfigurationEnumPropertyBuilder(source.GetOrAddPrimitivePropertyDefinition(expression, typeof(Enum)));
private static ConfigurationClassPropertyDefinition <TClass> GetOrAddClassPropertyDefinition <TModel, TClass>(this IModelWithProperties <TModel> source, LambdaExpression expression) where TClass : new() { var name = ExpressionHelper.GetPropertyNameFromExpression(expression); ConfigurationPropertyModelBase value; if (!source.ConfigurationProperties.TryGetValue(name, out value)) { var definition = new ConfigurationClassPropertyDefinition <TClass>(name, typeof(TClass), typeof(TModel)); ApplyDefaultPropertyDefinitions(definition); value = definition; source.ConfigurationProperties.Add(value.ConfigurationPropertyName, value); } var result = (ConfigurationClassPropertyDefinition <TClass>)value; return(result); }
private static ConfigurationFloatPropertyBuilder <TProperty> CreateForFloat <TModel, TProperty>(this IModelWithProperties <TModel> source, LambdaExpression expression) where TProperty : IComparable { return(new ConfigurationFloatPropertyBuilder <TProperty>(source.GetOrAddPrimitivePropertyDefinition(expression, typeof(TProperty)))); }
private static ConfigurationPrimitivePropertyModel GetOrAddPrimitivePropertyDefinition <TModel>(this IModelWithProperties <TModel> source, LambdaExpression expression, Type propertyType, bool isRequired) { var name = ExpressionHelper.GetPropertyNameFromExpression(expression); if (!source.ConfigurationProperties.TryGetValue(name, out ConfigurationPropertyModelBase value)) { value = new ConfigurationPrimitivePropertyModel(name, propertyType, typeof(TModel)); source.ConfigurationProperties.Add(value.ConfigurationPropertyName, value); } var result = (ConfigurationPrimitivePropertyModel)value; result.ValidationRules.IsRequired = isRequired; return(result); }
private static ConfigurationPrimitivePropertyModel GetOrAddPrimitivePropertyDefinition <TModel>(this IModelWithProperties <TModel> source, LambdaExpression expression, Type propertyType) { var name = ExpressionHelper.GetPropertyNameFromExpression(expression); ConfigurationPropertyModelBase value; if (!source.ConfigurationProperties.TryGetValue(name, out value)) { value = new ConfigurationPrimitivePropertyModel(name, propertyType, typeof(TModel)); source.ConfigurationProperties.Add(value.ConfigurationPropertyName, value); } return((ConfigurationPrimitivePropertyModel)value); }
/// <summary> /// Gets ConfigurationPropertyModelBuilder for integer value /// </summary> /// <typeparam name="TModel">Source model type</typeparam> /// <param name="source">model with property</param> /// <param name="expression">property selector</param> /// <returns>ConfigurationIntegerPropertyBuilder for selected property</returns> public static ConfigurationIntegerPropertyBuilder <uint> Property <TModel>(this IModelWithProperties <TModel> source, Expression <Func <TModel, uint?> > expression) => source.CreateForNullableInterger <TModel, uint>(expression);
/// <summary> /// Gets ConfigurationCollectionPropertyBuilder for a collection /// </summary> /// <typeparam name="TModel">Property parent Type</typeparam> /// <param name="source">model with property</param> /// <param name="expression">collection selector</param> /// <returns>ConfigurationCollectionPropertyBuilder for selected property</returns> public static ConfigurationIntegerCollectionPropertyBuilder <long> Collection <TModel>(this IModelWithProperties <TModel> source, Expression <Func <TModel, ICollection <long> > > expression) => source.IntegerPrimitiveCollection(expression);