Validation rule that compares two object properties.

Inherits: IValidationRule


The PropertiesComparisonRule class allows you to create a validation rule to compare two object properties.


Creates a new validation rule and sets its arguments. See

public PropertiesComparisonRule(string property1, string operation, string property2)

  • property1: string - a name of the first property to compare.
  • operation: string - a comparison operation: "==" ("=", “EQ”), “!= " ("<>”, “NE”); “<"/">” (“LT”/“GT”), “<="/">=” (“LE”/“GE”); “LIKE”.
  • property2: string - a name of the second property to compare.

Instance methods


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.


var schema = new ObjectSchema().WithRule(new PropertyComparisonRule("field1", "NE", "field2"));

schema.Validate({ field1: 1, field2: 2 });       // Result: no errors
schema.Validate({ field1: 1, field2: 1 });       // Result: field1 shall not be equal to field2
schema.Validate({ });                             // Result: no errors

See also