Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Rule sets on .ValidateAndThrow

$
0
0

There isn't a built in method for this, but it'd be trivial to add an extension:

public static class MyExtensions {
  public static void ValidateAndThrow(this IValidator validator, T instance, string ruleSet) {
    var result = validator.Validate(instance, ruleSet: ruleSet);

    if(! result.IsValid) {
      throw new ValidationException(result.Errors);	
    }
  }

}

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>