Validator.ValidateObject Method (Object, ValidationContext)

Determines whether the specified object is valid and throws a ValidationException if the object is not valid.

Namespace:  System.ComponentModel.DataAnnotations
Assembly:  System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)

public static void ValidateObject(
	Object instance,
	ValidationContext validationContext
)

Parameters

instance
Type: System.Object
The object to validate.
validationContext
Type: System.ComponentModel.DataAnnotations.ValidationContext
An object that contains information about the validation request.

ExceptionCondition
ArgumentNullException

instance is null.

-or-

validationContext is null.

ArgumentException

instance does not equal the ObjectInstance on validationContext.

ValidationException

instance is not valid.

The ValidateObject method evaluates each ValidationAttribute attribute that is associated with the object type. Class-level validation attributes are evaluated only if the property-level attributes are valid.

Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: