Pip-Services-Commons-Dotnet
Public Member Functions | Properties | List of all members
PipServices3.Commons.Validate.MapSchema Class Reference

Schema to validate maps. More...

Inheritance diagram for PipServices3.Commons.Validate.MapSchema:
PipServices3.Commons.Validate.Schema PipServices3.Commons.Validate.FilterParamsSchema

Public Member Functions

 MapSchema ()
 Creates a new instance of validation schema. More...
 
 MapSchema (object keyType, object valueType)
 Creates a new instance of validation schema and sets its values. More...
 
- Public Member Functions inherited from PipServices3.Commons.Validate.Schema
 Schema ()
 Creates a new instance of validation schema. More...
 
 Schema (bool required, List< IValidationRule > rules)
 Creates a new instance of validation schema and sets its values. More...
 
Schema MakeRequired ()
 Makes validated values always required (non-null). For null values the schema will raise errors. More...
 
Schema MakeOptional ()
 Makes validated values optional. Validation for null values will be skipped. More...
 
Schema WithRule (IValidationRule rule)
 Adds validation rule to this schema. This method returns reference to this exception to implement Builder pattern to chain additional calls. More...
 
List< ValidationResultValidate (object value)
 Validates the given value and results validation results. More...
 
void ValidateAndThrowException (string correlationId, object value, bool strict=false)
 Validates the given value and returns a ValidationException if errors were found. More...
 

Properties

object KeyType [get, set]
 
object ValueType [get, set]
 
- Properties inherited from PipServices3.Commons.Validate.Schema
bool IsRequired [get, set]
 
List< IValidationRuleRules [get, set]
 

Additional Inherited Members

- Protected Member Functions inherited from PipServices3.Commons.Validate.Schema
void PerformTypeValidation (string path, object type, object value, List< ValidationResult > results)
 Validates a given value to match specified type. The type can be defined as a Schema, type, a type name or TypeCode When type is a Schema, it executes validation recursively against that Schema. More...
 

Detailed Description

Schema to validate maps.

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

Constructor & Destructor Documentation

◆ MapSchema() [1/2]

PipServices3.Commons.Validate.MapSchema.MapSchema ( )

Creates a new instance of validation schema.

◆ MapSchema() [2/2]

PipServices3.Commons.Validate.MapSchema.MapSchema ( object  keyType,
object  valueType 
)

Creates a new instance of validation schema and sets its values.

Parameters
keyTypea type of map keys. Null means that keys may have any type.
valueTypea type of map values. Null means that values may have any type.

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