public static ValidationErrors Value(object target) { if (target == null) { throw new ArgumentNullException("target"); } // Self validation should be tried first; then the validator should be created ISelfValidation sv = target.Adapt <ISelfValidation>(); if (sv != null) { return(sv.Validate()); } Validator v = Validator.CreateSelfValidator(target.GetType()); if (v != null) { return(v.Validate(target)); } v = Validator.Create(target.GetType()); if (v != null) { return(v.Validate(target)); } throw ValidationFailure.ValidationNotDefined(); }
public void Add(ISelfValidation data, string prefix) { int total = data.Notifications.Messages.Count(); for (int i = 0; i < total; i++) { ValidationMessage message = (ValidationMessage)data.Notifications.Messages[i].Clone(); message.Reference = string.IsNullOrWhiteSpace(message.Reference) ? prefix : $"{prefix}.{message.Reference}"; this.Add(message); } }
public override ValidationErrors Validate(object target) { if (target == null) { return(ValidationErrors.None); } ISelfValidation s = target as ISelfValidation; if (s == null) { throw Failure.NotInstanceOf("target", target.GetType(), typeof(ISelfValidation)); } return(s.Validate()); }
public static ValidationNotification EqualItemsIsValid( this ISelfValidation source, IEnumerable value, IEnumerable compare, params IEnumerable[] compareMore) { compareMore = compareMore.Concat(new IEnumerable[] { value, compare }).ToArray(); return(source.Notifications.EqualItemsIsValid(compareMore)); }
public void Add(ISelfValidation data) { Messages = Messages.Concat(data.Notifications.Messages).ToList(); }
/// <summary> /// Testa se as espeficacoes do objeto estão satisfeitas /// </summary> /// <param name="entity">Entitdade a ser testada</param> /// <returns>Resultado da validação com sua(s) mensagem(ns) de erro correspondente, quando houver </returns> public virtual ValidationResult Validate(TEntity entity) { ISelfValidation validator = entity as ISelfValidation; return(validator.ValidationResult); }