Schema

Basic schema used to validate values against a set of validation rules.

Description

The Schema class provides a basic schema to validate values against a set of validation rules.

Important points

  • This schema is used as a basis for specific schemas to validate objects, project properties, arrays and maps.

Constructors

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

See IValidationRule

public Schema(bool required, List<IValidationRule> rules)

  • required: bool - (optional) true to always require non-null values.
  • rules: List<IValidationRule> - (optional) a list with validation rules.

Properties

IsRequired

Gets and sets a flag that always requires non-null values. For null values it raises a validation error.

public bool IsRequired [ get, set ]

Rules

Gets and sets validation rules to check values against.

public List<IValidationRule> Rules [ get, set ]

Instance methods

MakeOptional

Makes validated values optional. Validation for null values will be skipped. This method returns reference to this exception to implement Builder pattern to chain additional calls.

public Schema MakeOptional()

  • returns: Schema - this validation schema

MakeRequired

Makes validated values always required (non-null). For null values the schema will raise errors. This method returns reference to this exception to implement Builder pattern to chain additional calls.

public Schema MakeRequired()

  • returns: Schema - this validation schema

PerformTypeValidation

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.

protected void PerformTypeValidation(string path, object type, object value, List<ValidationResult> results)

  • path: string - a dot notation path to the value.
  • type: any - a type to match the value type
  • value: any - a value to be validated.
  • results: ValidationResult[] - a list with validation results to add new results.

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.

Validate

Validates the given value and results validation results. See ValidationResult

public List<ValidationResult> Validate(object value)

  • value: object - a value to be validated.
  • returns: List<ValidationResult> - a list with validation results.

ValidateAndReturnException!

TODO: this method is not realized yet for this language

Validates the given value and returns a ValidationException if errors were found.

public ValidationException ValidateAndReturnException(string correlationId, object value, bool strict = false)

  • correlationId: string - (optional) transaction id to trace execution through call chain.
  • value: object - a value to be validated.
  • strict: bool - true to treat warnings as errors.
  • returns: ValidationException - validation exception.

ValidateAndThrowException

Validates the given value and throws a ValidationException if errors were found.
See ValidationException.throwExceptionIfNeeded

public void ValidateAndThrowException(string correlationId, object value, bool strict = false)

  • correlationId: string - (optional) transaction id to trace execution through call chain.
  • value: object - a value to be validated.
  • strict: bool - true to treat warnings as errors.

WithRule

Adds validation rule to this schema. This method returns reference to this exception to implement Builder pattern to chain additional calls.

public Schema WithRule(IValidationRule rule)

See also