ValueComparisonRule

Validation rule that compares a value to a constant.

Inherits: IValidationRule

Description

The ValueComparisonRule class allows you to create a validation rule that compares a value to a constant.

Constructors

Creates a new validation rule and sets its values.

public ValueComparisonRule(string operation, object value)

  • operation: string - a comparison operation: "==" ("=", “EQ”), “!= " ("<>”, “NE”); “<"/">” (“LT”/“GT”), “<="/">=” (“LE”/“GE”); “LIKE”.
  • value: object - a constant value to compare to

Instance methods

Validate

Validates a given value against this rule.

public void Validate(string path, Schema schema, object value, List<ValidationResult> results)

  • path: string - a dot notation path to the value.
  • schema: Schema - a schema this rule is called from
  • value: object - a value to be validated.
  • results: List<ValidationResult> - a list with validation results to add new results.

Examples

var schema = new Schema().WithRule(new ValueComparisonRule("EQ", 1));

schema.Validate(1);          // Result: no errors
schema.Validate(2);          // Result: 2 is not equal to 1

See also