ValidationResult Class
Contains the results of a validation request.
Namespace: System.ComponentModel.DataAnnotations
Assembly: System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)
The ValidationResult type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | ValidationResult(String) | Initializes a new instance of the ValidationResult class with the specified error message. |
![]() | ValidationResult(String, IEnumerable<String>) | Initializes a new instance of the ValidationResult class with the specified error message and a collection of member names that are associated with the validation result. |
| Name | Description | |
|---|---|---|
![]() | ErrorMessage | Gets or sets the error message for the validation result. |
![]() | MemberNames | Gets the collection of member names associated with the validation result. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string value that represents the current validation result. (Overrides Object.ToString().) |
The ValidationResult class stores the outcome of a validation check. The IsValid and GetValidationResult methods return an instance of the ValidationResult class, which contains values to indicate whether the value of the entity member matches the validation attributes applied to that member.
If the value of the member successfully validates, the returned ValidationResult object equals the value of the Success field. To determine whether validation succeeded, you should check whether the returned object equals Success. If the value of the member does not validate, the returned ValidationResult object contains an error message and a collection of member names for the validation error, if they can be retrieved.
The following example shows how to return a validation result that indicates success or failure.
using System.ComponentModel.DataAnnotations; public class AWValidation { public static ValidationResult ValidateSalesPerson(string salesPerson) { bool isValid; // Perform validation logic here and set isValid to true or false. if (isValid) { return ValidationResult.Success; } else { return new ValidationResult( "The selected sales person is not available for this customer."); } } public static ValidationResult ValidateAddress(CustomerAddress addressToValidate) { bool isValid; // Perform validation logic here and set isValid to true or false. if (isValid) { return ValidationResult.Success; } else { return new ValidationResult( "The address for this customer does not match the required criteria."); } } }
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
