NotRule

Validation rule used to negate another rule.

Inherits: IValidationRule

Description

The NotRule class allows you to negate a rule. Thus, when the embedded rule returns errors, then the negated rule returns no errors and vice versa.

Constructors

Creates a new validation rule and sets its values.

public NotRule(IValidationRule rule)

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 NotRule(new ValueComparisonRule("EQ", 1)));

schema.Validate(1);          // Result: error
schema.Validate(5);          // Result: no error

See also