Schema to validate object properties

Inherits: Schema


The PropertySchema class allows you to create schemas to validate object properties.


Creates a new validation rule and sets its arguments. See IValidationRule, TypeCode

public PropertySchema(string name, object type)

  • name: string - (optional) a property name
  • type: object - (optional) a property type

Creates a new validation schema.

public PropertySchema()



Gets and sets the property name.

public string Name [ get, set ]


Gets and sets the property type. The type can be defined as type, type name or TypeCode

public object Type [ get, set ]

Instance methods


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

public 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.


var schema = new ObjectSchema().WithProperty(new PropertySchema("id", TypeCode.String));

schema.Validate({ id: "1", name: "ABC" });       // Result: no errors
schema.Validate({ name: "ABC" });                // Result: no errors
schema.Validate({ id: 1, name: "ABC" });         // Result: id type mismatch

See also