public override PropertyConstraintViolationError Validate(object value, PropertyDefinition propertyDefinition, IPropertyBag propertyBag)
 {
     if (!Enum.IsDefined(this.enumType, value))
     {
         return(new PropertyConstraintViolationError(DataStrings.ConstraintViolationEnumValueNotDefined(value.ToString(), propertyDefinition.Type.Name), propertyDefinition, value, this));
     }
     return(null);
 }
Beispiel #2
0
        public static int ValidateEnumValue(string enumValue, string typeName, int min, int max)
        {
            if (enumValue == null)
            {
                throw new ArgumentNullException("enumValue");
            }
            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentException("typeName");
            }
            int num;

            if (!int.TryParse(enumValue, out num) || num < min || num > max)
            {
                throw new FormatException(DataStrings.ConstraintViolationEnumValueNotDefined(enumValue, typeName));
            }
            return(num);
        }