Validator.TryValidateValue Metódus

Definíció

Olyan értéket ad vissza, amely jelzi, hogy a megadott érték érvényes-e a megadott attribútumokkal.

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

Paraméterek

value
Object

Az érvényesítendő érték.

validationContext
ValidationContext

Az érvényesítendő objektumot leíró környezet.

validationResults
ICollection<ValidationResult>

Sikertelen érvényesítések tárolására használható gyűjtemény.

validationAttributes
IEnumerable<ValidationAttribute>

Az érvényesítési attribútumok.

Válaszok

trueha az objektum érvényesítve van; egyéb esetben. false

Megjegyzések

Ez a módszer teszteli a validationAttributes paraméterben lévő összes érvényesítési attribútumot a value paraméteren. Ha a paraméter nemvalidationResults, ez a null metódus minden érvényesítési hibához hozzáad egy ValidationResult objektumot az érvényesítési eredmények gyűjteményéhez. Ha a validationResults paraméter az null, ez a metódus nem ad hozzá objektumot ValidationResult a gyűjteményhez. Ha egy RequiredAttribute attribútum szerepel a validationAttributes paraméterben, először az RequiredAttribute attribútum lesz kiértékelve.

A következőre érvényes: