Jaa


Understanding Validation Results

The ValidationResults type is a collection of ValidationResult objects. Each ValidationResult object contains a report that includes references to the Validator instance, the object that was validated, and error messages.

The following table lists the properties and methods of the ValidationResults collection class.

Member

Description

AddAllResults

Takes a collection of ValidationResult instances and adds them to an existing ValidationResults instance.

AddResult

Creates a new ValidationResult instance and adds it to an existing ValidationResults instance.

Count

Returns the number of ValidationResult instances in the collection.

FindAll

Filters a ValidationResults instance and eliminates results that do not match the value of the Tag property that was specified for the validator. This method returns a new ValidationResults object that contains the required set of ValidationResult instances and leaves the original ValidationResults instance unchanged.

IsValid

This property returns true if validation succeeded or false if validation failed.

The following table lists the properties of the ValidationResult class.

Property

Description

Key

This is a name that describes the location of the validation result. It contains the name of the member that is associated with the validator. It is null if the validator is defined at the type level.

NestedVlidationResults

The nested validation results for a composite failed validation.

Message

This is a message that describes the validation failure.

Tag

This is a value supplied by the user as the Tag property of the validator. Typically, it is used for categorization or filtering. The tag can be supplied through the constructor but it is typically set either by using a property in the validation attributes or with configuration.

Target

This is the object to which the validation rule was applied.

Validator

This is the validator that performed the validation.