共用方式為


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先評估屬性。

適用於