Esempio n. 1
0
        public ValidationResult Validate(T candidate)
        {
            var result = new ValidationResult();

            if (candidate == null)
            {
                result.AddReason(MessageInvalidationReason.Error(InvalidMessageKey));
                return(result);
            }

            var stringCandidate = candidate as string;

            if (candidate is string && string.IsNullOrEmpty(stringCandidate))
            {
                result.AddReason(MessageInvalidationReason.Error(InvalidMessageKey));
            }

            var enumerableCandidate = candidate as IEnumerable <object>;

            if (enumerableCandidate != null && !enumerableCandidate.GetEnumerator().MoveNext())
            {
                result.AddReason(MessageInvalidationReason.Error(InvalidMessageKey));
            }

            return(result);
        }
        public ValidationResult Validate(string email)
        {
            var result = new ValidationResult();

            if (email != null)
            {
                var match = emailRegex.Match(email);
                if (!match.Success)
                {
                    result.AddReason(MessageInvalidationReason.Error(InvalidMessageKey, email));
                }
            }
            return(result);
        }
Esempio n. 3
0
        public ValidationResult Validate(T candidate)
        {
            var result = new ValidationResult();

            var length = ExtractLength(candidate);

            if (min.HasValue && length < min.Value)
            {
                result.AddReason(MessageInvalidationReason.Error(InvalidMinMessageKey, length, min));
            }
            if (max.HasValue && length > max.Value)
            {
                result.AddReason(MessageInvalidationReason.Error(InvalidMaxMessageKey, length, max));
            }

            return(result);
        }
 public PropertyInvalidationReason(string typeName, string propertyName, string messageKey, params object[] parameters) :
     this(typeName, propertyName, MessageInvalidationReason.Error(messageKey, parameters))
 {
 }