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.
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)
Properties
ValidationErr
provides access to the underlying validation result's failure properties:
Errors
: the list of validation failures as exposed by theValidationResult
RuleSetsExecuted
: the array of rulesets executed as exposed by theValidationResult
Methods
ValidationErr
provides the following helper methods:
ToDictionary()
: converts theValidationResult
into a dictionaryToString()
: converts theValidationResult
into a stringAsValidationResult()
: provides access to the underlyingValidationResult
Last updated
Was this helpful?