Including Validators

Validatum allows for multiple validators to be used with other validators. This promotes the reuse of validators targeting the same type.


Example Usage

Using same type instance.

var rangeValidator = new ValidatorBuilder<int>()
    .Range(18, 52)
    .Build();

var numberValidator = new ValidatorBuilder<int>()
    .Validator(rangeValidator)
    .Build();

var result = numberValidator.Validate(42);

Using selector expression.

var ageValidator = new ValidatorBuilder<int>()
    .Range(18, 52)
    .Build();

var personValidator = new ValidatorBuilder<Person>()
    .Validator(p => p.Age, ageValidator)
    .Build();

var result = personValidator.Validate(new Person { Name = "Rob", Age = 28 });

Using For function.

var ageValidator = new ValidatorBuilder<int>()
    .Range(18, 52)
    .Build();

var personValidator = new ValidatorBuilder<Person>()
    .For(p => p.Age, v => v.Validator(ageValidator))
    .Build();

var result = personValidator.Validate(new Person { Name = "Jez", Age = 28 });