question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Combine multiple ValidationResults

See original GitHub issue

Is 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:closed
  • Created 2 months ago
  • Reactions:1
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
JeremySkinnercommented, Aug 12, 2023

I’ve pushed out 11.7.1 with this fix

1reaction
JeremySkinnercommented, Aug 8, 2023

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found