Validator.ValidateObject Method (Object, ValidationContext, Boolean)
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Determines whether the specified object is valid and, if requested, whether all of the properties on the object are 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, _
validateAllProperties As Boolean _
)
public static void ValidateObject(
Object instance,
ValidationContext validationContext,
bool validateAllProperties
)
Parameters
- instance
Type: System.Object
The object to validate.
- validationContext
Type: System.ComponentModel.DataAnnotations.ValidationContext
An object that contains information about the validation request.
- validateAllProperties
Type: System.Boolean
A value that indicates whether all immediate properties of the object are validated.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | instance is null. -or- validationContext is null. |
ArgumentException | instance does not equal the ObjectInstance on validationContext. |
ValidationException | instance or at least one of its properties is not valid. |
Remarks
The ValidateObject method evaluates each ValidationAttribute attribute that is associated with the object type. If validateAllProperties is set to true, the method validates the property values of the object. 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.
See Also