Validation rule that allows you to check combinations of rules created with OR logical operations.
Inherits: IValidationRule
Description
The OrRule class allows you to validate combinations of rules created with OR logical operations.
Important points
- When one of the combined rules returns no errors, then this rule also returns no errors.
- When all combined rules return errors, then this rule returns all the errors.
Constructors
Creates a new validation rule and sets its values.
public
OrRule(params IValidationRule[] rules)
- rules: IValidationRule[] - list of rules to join with OR operators
Instance methods
Validate
Validates a given value against this rule.
public
void Validate(string path, Schema schema, object value, List<ValidationResult> results)
- path: string - path to the value in dot notation.
- schema: Schema - schema this rule is called from
- value: object - value to be validated.
- results: List<ValidationResult> - list with validation results to add new results.
Examples
var schema = new Schema().WithRule(new OrRule(new ValueComparisonRule("LT", 1),
new ValueComparisonRule("GT", 10)));
schema.Validate(0); // Result: no error
schema.Validate(5); // Result: 5 must be less than 1 or 5 must be more than 10
schema.Validate(20); // Result: no error