Validation Results

After executing a validator the Validate() method will return aValidationResult instance.

The ValidationResult class encapsulates the broken rules collection.


Properties
IsValid

Indicates whether the result is valid.

Example Usage
var validator = new ValidatorBuilder<int>()
    .Range(50, 100)
    .Build();
    
// get the validation result
var result = validator.Validate(49);

// check valid status
if (result.IsValid)
{
    Console.WriteLine("All good.");
}
else
{
    Console.WriteLine("Something is amiss!");
}

BrokenRules

A collection containing BrokenRule items.

Example Usage
var validator = new ValidatorBuilder<string>()
    .StartsWith("Alexander")
    .Contains("the")
    .EndsWith("Great")
    .Build();
    
// get the validation result
var result = validator.Validate("Homer the Lazy");

// check the broken rules collection
foreach (var rule in result.BrokenRules)
{
    Console.WriteLine($"[{rule.Rule}] {rule.Key}: {rule.Message}");
}

// output
// [StartsWith] String: Value must start with 'Alexander'.
// [EndsWith] String: Value must end with 'Great'.