Combine multiple ValidationResults
See original GitHub issueIs your feature request related to a problem? Please describe.
No, just a useful method that I could not find in the lib. Is there any “native” way to combine/join multiples ValidationResult’s?
Describe the solution you’d like
It is very useful to combine/join mutiples ValidationResults into a new ValidationResults, for example…
ValidationResult fullValidation = new[]
{
ValidationA(obj),
ValidationB(obj),
ValidationC(obj),
}
.Combine();
ValidationResult ValidationA(Person x) { ... }
ValidationResult ValidationB(Person x) { ... }
ValidationResult ValidationC(Person x) { ... }
Describe alternatives you’ve considered
In my current system I’ve added the following extension methods. If there are interest to make them part of the library (in case of no current native solution) I can submit a PR.
public static ValidationResult Combine(this ValidationResult validationResult, params ValidationResult[] failuresResult)
{
return failuresResult.Append(validationResult).Combine();
}
public static ValidationResult Combine(this IEnumerable<ValidationResult> failuresResult)
{
var errors = failuresResult.SelectMany(x => x.Errors);
return new ValidationResult(errors);
}
Additional Context
No response
Issue Analytics
- State:
- Created 2 months ago
- Reactions:1
- Comments:10 (8 by maintainers)
Top Results From Across the Web
c# - Returning multiple ValidationExceptions
Answer your first question: Because each validation attribute have their own IsValid property and return public ValidationResult(string ...
Read more >How should I report multiple errors as a result of validation?
I would record the errors separately rather than concatenate them (that ... Then you can build up your validation result as you validate ......
Read more >org.controlsfx.validation.ValidationResult.combineAll java ...
Combine validation result with others. This will create a new instance of combined validation result * @param validationResults * @return new instance of ......
Read more >ValidationResult (ControlsFX Project 11.1.0)
Combine validation result with another. ValidationResult, combineAll(Collection<ValidationResult> validationResults). Combine validation result with others.
Read more >Aggregation of validation - Niche Software
How do we make it easy for our consumers to combine multiple validation results together into one. Ideally, we want this to be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve pushed out 11.7.1 with this fix
Added the new constructor in 1f9102d8a. This will go in the 11.7 release.
I’m not keen on including the extension methods in the library, I don’t feel they’re necessary, but you can continue to use them within your own project.