ValidationErr

This library wraps the ValidationResult provided by FluentValidation inside the ValidationErr class. ValidationErr is designed to capture and expose validation failures in a way that integrates smoothly with the functional patterns provided by Waystone.Monads.

ValidationErr isolates the failure case of the ValidationResult

Creation

A ValidationErr can be created by invoking the Create factory method and providing it with a ValidationResult. The factory will return an Option<T> of ValidationErr which will be Some if the provided ValidationResult is invalid.

class GreaterThanZeroValidator : AbstractValidator<int>
{
    public GreaterThanZeroValidator()
    {
         RuleFor(x => x).GreaterThanZero();   
    }
}

int x = -1;
GreaterThanZeroValidator validator = new();
ValidationResult result = validator.Validate(x);
Option<ValidationErr> maybeValidationErr = ValidationErr.Create(result);
//                    ^? Some(ValidationErr)

In most cases, you will want to use the Validate or ValidateAsync extension methods instead.

Properties

ValidationErr provides access to the underlying validation result's failure properties:

  • Errors: the list of validation failures as exposed by the ValidationResult

  • RuleSetsExecuted: the array of rulesets executed as exposed by the ValidationResult

Methods

ValidationErr provides the following helper methods:

  • ToDictionary(): converts the ValidationResult into a dictionary

  • ToString(): converts the ValidationResult into a string

  • AsValidationResult(): provides access to the underlying ValidationResult

Last updated

Was this helpful?