private ValidationResult ValidateProperty(object target, ConfigurationPrimitivePropertyModel propertyModel)
        {
            var errors        = new List <string>();
            var propertyValue = propertyModel.GetPropertyValue(target);

            if (propertyValue == null)
            {
                return(propertyModel.ValidationRules.IsRequired
                    ? new ValidationResult(ValidationStrings.RequiredPropertyNotFound(propertyModel.ConfigurationPropertyName))
                    : ValidationResult.CreateValid());
            }
            if (propertyModel.ValidationRules.Min != null && propertyModel.ValidationRules.Min.CompareTo(propertyValue) > 0)
            {
                errors.Add(ValidationStrings.LessThanMin(propertyModel.ConfigurationPropertyName, propertyModel.ValidationRules.Min));
            }
            if (propertyModel.ValidationRules.Max != null && propertyModel.ValidationRules.Max.CompareTo(propertyValue) < 0)
            {
                errors.Add(ValidationStrings.GreaterThanMax(propertyModel.ConfigurationPropertyName, propertyModel.ValidationRules.Max));
            }
            if (propertyValue is string stringProperty)
            {
                ValidateStringProperty(stringProperty, propertyModel, errors);
            }
            return(new ValidationResult(errors));
        }
 private void ValidateStringProperty(string target, ConfigurationPrimitivePropertyModel propertyModel, List <string> errors)
 {
     if (propertyModel.ValidationRules.MaxLength.HasValue && target.Length > propertyModel.ValidationRules.MaxLength)
     {
         errors.Add(ValidationStrings.GreaterThanMaxLength(propertyModel.ConfigurationPropertyName, propertyModel.ValidationRules.MaxLength));
     }
     if (!string.IsNullOrWhiteSpace(propertyModel.ValidationRules.Pattern) && !Regex.IsMatch(target, propertyModel.ValidationRules.Pattern))
     {
         errors.Add(ValidationStrings.MatchesPattern(propertyModel.ConfigurationPropertyName, propertyModel.ValidationRules.Pattern));
     }
 }
        private ValidationResult ValidateProperty(object target, ConfigurationPrimitivePropertyModel propertyModel)
        {
            var errors        = new List <string>();
            var propertyValue = propertyModel.GetPropertyValue(target);

            if (propertyModel.ValidationRules.Min != null && propertyModel.ValidationRules.Min.CompareTo(propertyValue) > 0)
            {
                errors.Add(string.Format(ValidationStrings.LessThanMin, propertyModel.ConfigurationPropertyName, propertyModel.ValidationRules.Min));
            }
            if (propertyModel.ValidationRules.Max != null && propertyModel.ValidationRules.Max.CompareTo(propertyValue) < 0)
            {
                errors.Add(string.Format(ValidationStrings.GreaterThanMax, propertyModel.ConfigurationPropertyName, propertyModel.ValidationRules.Max));
            }
            if (propertyModel.ValidationRules.MaxLength.HasValue && propertyValue is string && ((string)propertyValue).Length > propertyModel.ValidationRules.MaxLength)
            {
                errors.Add(string.Format(ValidationStrings.GreaterThanMaxLength, propertyModel.ConfigurationPropertyName, propertyModel.ValidationRules.MaxLength));
            }
            if (!string.IsNullOrWhiteSpace(propertyModel.ValidationRules.Pattern) && propertyValue is string && !Regex.IsMatch((string)propertyValue, propertyModel.ValidationRules.Pattern))
            {
                errors.Add(string.Format(ValidationStrings.MatchesPattern, propertyModel.ConfigurationPropertyName, propertyModel.ValidationRules.Pattern));
            }
            return(new ValidationResult(errors));
        }
 /// <summary>
 /// Initializes ConfigurationStringPropertyBuilder for given ConfigurationPropertyModel
 /// </summary>
 /// <param name="model">ConfigurationPropertyModel to be modified by ConfigurationPropertyModelBuilder</param>
 internal ConfigurationStringPropertyBuilder(ConfigurationPrimitivePropertyModel model) : base(model)
 {
 }
 /// <summary>
 /// Initializes ConfigurationEnumPropertyBuilder for given ConfigurationPropertyModel
 /// </summary>
 /// <param name="model">ConfigurationPropertyModel to be modified by ConfigurationPropertyModelBuilder</param>
 public ConfigurationEnumPropertyBuilder(ConfigurationPrimitivePropertyModel model) : base(model)
 {
 }