Editare

Partajați prin


Validator.TryValidateValue Method

Definition

Returns a value that indicates whether the specified value is valid with the specified attributes.

public:
 static bool TryValidateValue(System::Object ^ value, System::ComponentModel::DataAnnotations::ValidationContext ^ validationContext, System::Collections::Generic::ICollection<System::ComponentModel::DataAnnotations::ValidationResult ^> ^ validationResults, System::Collections::Generic::IEnumerable<System::ComponentModel::DataAnnotations::ValidationAttribute ^> ^ validationAttributes);
public static bool TryValidateValue (object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> validationResults, System.Collections.Generic.IEnumerable<System.ComponentModel.DataAnnotations.ValidationAttribute> validationAttributes);
public static bool TryValidateValue (object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults, System.Collections.Generic.IEnumerable<System.ComponentModel.DataAnnotations.ValidationAttribute> validationAttributes);
public static bool TryValidateValue (object? value, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults, System.Collections.Generic.IEnumerable<System.ComponentModel.DataAnnotations.ValidationAttribute> validationAttributes);
static member TryValidateValue : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> * seq<System.ComponentModel.DataAnnotations.ValidationAttribute> -> bool
Public Shared Function TryValidateValue (value As Object, validationContext As ValidationContext, validationResults As ICollection(Of ValidationResult), validationAttributes As IEnumerable(Of ValidationAttribute)) As Boolean

Parameters

value
Object

The value to validate.

validationContext
ValidationContext

The context that describes the object to validate.

validationResults
ICollection<ValidationResult>

A collection to hold failed validations.

validationAttributes
IEnumerable<ValidationAttribute>

The validation attributes.

Returns

true if the object validates; otherwise, false.

Remarks

This method tests each validation attribute in the validationAttributes parameter against the value parameter. If the validationResults parameter is not null, this method adds a ValidationResult object for each validation failure to the validation results collection. If the validationResults parameter is null, this method does not add a ValidationResult object to the collection. If a RequiredAttribute attribute is included in the validationAttributes parameter, the RequiredAttribute attribute is evaluated first.

Applies to