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(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 override ValidationResult Validate(T candidate) { var result = new ValidationResult(); var valueResult = base.Validate(candidate); foreach (PropertyInvalidationReason reason in valueResult.Reasons().Select(r => new PropertyInvalidationReason(typeName, propertyName, r))) { result.AddReason(reason); } 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); }
public ValidationResult Merge(ValidationResult other) { if (this.reasonsBySeverity.Count == 0) { return(other); } else if (other.reasonsBySeverity.Count == 0) { return(this); } var newResult = new ValidationResult(); foreach (IInvalidationReason reason in other.Reasons().Concat(this.Reasons())) { newResult.AddReason(reason); } return(newResult); }