MapSchema

Schema to validate maps.

Inherits: Schema

Description

The MapSchema class provides you with a schema to validate maps

Constructors

Creates a new instance of validation schema and sets its values. See IValidationRule, TypeCode

public MapSchema(object keyType, object valueType)

  • keyType: object - a type of map keys. Null means that keys may have any type.
  • valueType: object - a type of map values. Null means that values may have any type.

Creates a new instance of validation schema.

public MapSchema()

Properties

KeyType

Gets and sets the type of map keys. Null means that keys may have any type.

public object KeyType [ get, set ]

ValueType

Gets and sets the type of map values. Null means that values may have any type.

public object ValueType [ get, set ]

Instance methods

PerformValidation

Validates a given value against the schema and configured validation rules.

protected internal override void PerformValidation(string path, object value, List<ValidationResult> results)

  • path: string - a dot notation path to the value.
  • value: object - a value to be validated.
  • results: List<ValidationResult> - a list with validation results to add new results.

Examples

var schema = new MapSchema(TypeCode.String, TypeCode.Integer);

schema.Validate({ "key1": "A", "key2": "B" });       // Result: no errors
schema.Validate({ "key1": 1, "key2": 2 });           // Result: element type mismatch
schema.Validate(new int[]{ 1, 2, 3 });                        // Result: type mismatch