In Validatum all validation begins with the ValidatorBuilder<T> class. You must create an instance of this class in order to build a Validator<T> to validate values. Any type can be used to create a ValidatorBuilder.
The ValidatorBuilder<T> class provides a default implementation of the IValidatorBuilder<T> interface.
This class provides two important functions:
This method is used to add validation functions to the builder.
var builder = new ValidatorBuilder<int>()
.With(ctx =>
{
// perform validation
if (context.Value == 13)
{
context.AddBrokenRule("NotThirteen", "Unlucky", "Value cannot equal 13");
}
});
This method is used to create a Validator<T> instance.
var validator = new ValidatorBuilder<string>()
.Required()
.Build(); // builds a Validator<string> instance
// use the validator
var result = validator.Validate("hello");