Exemplo n.º 1
0
        private static void ValidateAttributeValidation(ValidateAttribute attribute, object value, PropertyInfo property, Errors errors)
        {
            if (attribute.Required)
            {
                RequiredAttribute.Validate(property, value, errors);
            }

            if (attribute.MinLength > 0)
            {
                MinLengthAttribute.Validate(property, value, errors);
            }

            if (attribute.MaxLength > 0)
            {
                MaxLengthAttribute.Validate(property, value, errors);
            }
        }
Exemplo n.º 2
0
        private static Info ValidateMaxLengthAttribute(PropertyInfo property, object value, MaxLengthAttribute maxLength, Errors errors)
        {
            if (!property.PropertyType.Equals(typeof(string)))
            {
                throw new ArgumentException("Invalid Argument Type");
            }

            var strValue = value as string;

            if (strValue?.Length > maxLength.Length)
            {
                return(property.GetInfo(InfoType.MaxLengthObject));
            }

            return(null);
        }