Validator.TryValidateValue Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Determines whether a specified value is valid against a collection of validation attributes.
Namespace: System.ComponentModel.DataAnnotations
Assembly: System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)
Syntax
'Declaration
Public Shared Function TryValidateValue ( _
value As Object, _
validationContext As ValidationContext, _
validationResults As ICollection(Of ValidationResult), _
validationAttributes As IEnumerable(Of ValidationAttribute) _
) As Boolean
public static bool TryValidateValue(
Object value,
ValidationContext validationContext,
ICollection<ValidationResult> validationResults,
IEnumerable<ValidationAttribute> validationAttributes
)
Parameters
- value
Type: System.Object
The value to validate.
- validationContext
Type: System.ComponentModel.DataAnnotations.ValidationContext
An object that contains information about the validation request.
- validationResults
Type: System.Collections.Generic.ICollection<ValidationResult>
A collection to store validation results.
- validationAttributes
Type: System.Collections.Generic.IEnumerable<ValidationAttribute>
The collection of validation attributes to use to determine if value is valid.
Return Value
Type: System.Boolean
true if value is valid against the validation attributes; otherwise, false.
Remarks
The TryValidateValue method tests each validation attribute in the validationAttributes parameter against the value parameter. If a RequiredAttribute attribute is included, the RequiredAttribute attribute is evaluated first.
If validationResults is nulla null reference (Nothing in Visual Basic), the method stops at the first validation failure. If validationResults is not nulla null reference (Nothing in Visual Basic), the method evaluates all validation attributes and adds all of the failures to validationResults.
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