Exemplo n.º 1
0
 private string GetPropertyType(ConfigurationPrimitivePropertyModel definition)
 {
     if (IsIntergerType(definition.PropertyType))
     {
         return(ConfigurationPropertyType.Interger);
     }
     if (IsFloatType(definition.PropertyType))
     {
         return(ConfigurationPropertyType.Float);
     }
     if (definition.PropertyType == typeof(string))
     {
         return(ConfigurationPropertyType.String);
     }
     if (definition.PropertyType == typeof(bool))
     {
         return(ConfigurationPropertyType.Bool);
     }
     if (definition.PropertyType == typeof(DateTime) || definition.PropertyType == typeof(DateTime?))
     {
         return(ConfigurationPropertyType.DateTime);
     }
     if (typeof(Enum).IsAssignableFrom(definition.PropertyType))
     {
         return(ConfigurationPropertyType.Enum);
     }
     return(ConfigurationPropertyType.Unacceptable);
 }
        public static ConfigurationPropertyModelBase Build(string propertyName, Type type, Type parentType)
        {
            var propertyModel = new ConfigurationPrimitivePropertyModel(propertyName, type, parentType);
            var typeInfo      = type.GetTypeInfo();

            propertyModel.ValidationRules.IsRequired = !(typeInfo.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>));

            return(propertyModel);
        }
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        private ConfigurationPropertyPayload BuildProperty(ConfigurationPrimitivePropertyModel value)
        {
            var propertyType = propertyTypeProvider.GetPropertyType(value);

            return(new ConfigurationPropertyPayload
            {
                PropertyName = value.ConfigurationPropertyName.ToLowerCamelCase(),
                PropertyDisplayName = value.PropertyDisplayName,
                PropertyType = propertyType,
                ValidationDefinition = value.ValidationRules,
                PropertyDescription = value.PropertyDescription,
                Options = propertyType == ConfigurationPropertyType.Enum? BuildEnumOption(value.PropertyType) : new Dictionary <string, string>()
            });
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes ConfigurationFloatPropertyBuilder for given ConfigurationPropertyModel
 /// </summary>
 /// <param name="model">ConfigurationPropertyModel to be modified by ConfigurationPropertyModelBuilder</param>
 internal ConfigurationFloatPropertyBuilder(ConfigurationPrimitivePropertyModel model) : base(model)
 {
 }