Pip-Services-Commons-Dotnet
Public Member Functions | Private Attributes | List of all members
PipServices3.Commons.Validate.OnlyOneExistsRule Class Reference

Validation rule that check that at exactly one of the object properties is not null. More...

Inheritance diagram for PipServices3.Commons.Validate.OnlyOneExistsRule:
PipServices3.Commons.Validate.IValidationRule

Public Member Functions

 OnlyOneExistsRule (params string[] properties)
 Creates a new validation rule and sets its values More...
 
void Validate (string path, Schema schema, object value, List< ValidationResult > results)
 Validates a given value against this rule. More...
 

Private Attributes

readonly string [] _properties
 

Detailed Description

Validation rule that check that at exactly one of the object properties is not null.

var schema = new Schema().WithRule(new OnlyOneExistsRule("field1", "field2"));
schema.Validate({ field1: 1, field2: "A" }); // Result: only one of properties field1, field2 must exist
schema.Validate({ field1: 1 }); // Result: no errors
schema.Validate({ }); // Result: only one of properties field1, field2 must exist

See IValidationRule

Constructor & Destructor Documentation

◆ OnlyOneExistsRule()

PipServices3.Commons.Validate.OnlyOneExistsRule.OnlyOneExistsRule ( params string []  properties)

Creates a new validation rule and sets its values

Parameters
propertiesa list of property names where at only one property must exist

Member Function Documentation

◆ Validate()

void PipServices3.Commons.Validate.OnlyOneExistsRule.Validate ( string  path,
Schema  schema,
object  value,
List< ValidationResult results 
)

Validates a given value against this rule.

Parameters
patha dot notation path to the value.
schemaa schema this rule is called from
valuea value to be validated.
resultsa list with validation results to add new results.

Implements PipServices3.Commons.Validate.IValidationRule.


The documentation for this class was generated from the following file: