Validator.TryValidateValue 方法

定义

返回一个值,该值指示所指定值对所指定特性是否有效。

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

参数

value
Object

要验证的值。

validationContext
ValidationContext

用于描述要验证的对象的上下文。

validationResults
ICollection<ValidationResult>

用于包含失败的验证的集合。

validationAttributes
IEnumerable<ValidationAttribute>

验证特性。

返回

如果对象有效,则为 true;否则为 false

注解

此方法针对 value 参数测试 参数中的每个validationAttributes验证属性。 validationResults如果 参数不是 null,则此方法会将每个验证失败的对象添加到ValidationResult验证结果集合。 validationResults如果 参数为 null,则此方法不会将 对象添加到ValidationResult集合。 RequiredAttribute如果属性包含在 参数中validationAttributes,则首先计算该RequiredAttribute属性。

适用于