public override IValidationResult Validate(T instance) { var nested = _expression.Compile().Invoke(instance); if (WhenCondition != null && !WhenCondition(instance)) { return(null); } var validator = _validator.Invoke(); var summary = validator.Validate(nested); if (summary.IsValid) { return(null); } var builder = new SummaryMessageBuilder(summary.ValidationResults); var message = builder.BuildMessage <T>(); return(new ValidationResult(Severity.Error, message)); }
public override IValidationResult Validate(T instance) { if (WhenCondition != null && !WhenCondition(instance)) { return(null); } var nestedEnumeration = _expression.Compile().Invoke(instance); if (nestedEnumeration == null) { throw new ArgumentNullException(nameof(instance)); } var validator = _validator.Invoke(); var summaries = new List <IValidationSummary>(); foreach (var nested in nestedEnumeration) { var summary = validator.Validate(nested); if (!summary.IsValid) { summaries.Add(summary); } } if (!summaries.Any()) { return(null); } var results = summaries.SelectMany(s => s.ValidationResults); var builder = new SummaryMessageBuilder(results); var message = builder.BuildMessage <T>(); return(new ValidationResult(Severity.Error, message)); }
private string GetValidationMessage() { var builder = new SummaryMessageBuilder(ValidationResults); return(builder.BuildMessage <T>()); }
public string GetInfoMessage() { var builder = new SummaryMessageBuilder(ValidationResults); return(builder.BuildMessage(Severity.Info)); }