This project is read-only.

Validate Objects and Properties


Validate with Default Specification

var validationResult = ValidationCatalog.Validate(object);

Validate with Explicit Specification

var validationResult = ValidationCatalog.Validate(object, MySpecification);
var validationResult = ValidationCatalog.Validate<MySpecification>(object);


//Strongly Typed
var validationResult = ValidationCatalog.ValidateProperty(contact, c => c.LastName);

//Dynamically Typed
var validationResult = ValidationCatalog.ValidateProperty(contact, "LastName");

If you try validating a Property for which no rule exists, an ArgumentException will be thrown.

Handling Validation Exceptions

The ValidationNotification object contains all the broken validation rules for a Validate call. This type is contains a collection of ValidationResult objects.

A ValidationResult object contains details about a single broken rule and contains
  • Property the rule is for
  • Error message
  • The actual object the rules were run against
  • Collection of Nested ValidationResults. If you validate a deep object graph, this will contain all validation result for the children objects. For example if a Class has a collection that is validated, a ValidationResult for the collection will contain all the broken items in the collection.

Example of Nested Validation Results


Last edited May 3, 2010 at 6:14 PM by TechnoAg, version 3


No comments yet.