Поделиться через


Validator.ValidateObject Method (Object, ValidationContext)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Shared Sub ValidateObject ( _
    instance As Object, _
    validationContext As ValidationContext _
)
public static void ValidateObject(
    Object instance,
    ValidationContext validationContext
)

Parameters

Exceptions

Exception Condition
ArgumentNullException

instance is null.

-or-

validationContext is null.

ArgumentException

instance does not equal the ObjectInstance on validationContext.

ValidationException

instance is not valid.

Remarks

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.

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

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