Validator.TryValidateObject Metódus

Definíció

Meghatározza, hogy a megadott objektum érvényes-e.

Túlterhelések

Name Description
TryValidateObject(Object, ValidationContext, ICollection<ValidationResult>)

Meghatározza, hogy a megadott objektum érvényes-e az érvényesítési környezet és az érvényesítési eredmények gyűjteményének használatával.

TryValidateObject(Object, ValidationContext, ICollection<ValidationResult>, Boolean)

Meghatározza, hogy a megadott objektum érvényes-e az érvényesítési környezet, az érvényesítési eredmények gyűjteményének és egy olyan értéknek a használatával, amely meghatározza, hogy az összes tulajdonság érvényesíthető-e.

TryValidateObject(Object, ValidationContext, ICollection<ValidationResult>)

Forrás:
Validator.cs
Forrás:
Validator.cs
Forrás:
Validator.cs
Forrás:
Validator.cs
Forrás:
Validator.cs

Meghatározza, hogy a megadott objektum érvényes-e az érvényesítési környezet és az érvényesítési eredmények gyűjteményének használatával.

public:
 static bool TryValidateObject(System::Object ^ instance, System::ComponentModel::DataAnnotations::ValidationContext ^ validationContext, System::Collections::Generic::ICollection<System::ComponentModel::DataAnnotations::ValidationResult ^> ^ validationResults);
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> validationResults);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Constructing a ValidationContext without a display name is not trim-safe because it uses reflection to discover the type of the instance being validated in order to resolve the DisplayNameAttribute when a display name is not provided.")]
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults);
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")]
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults);
static member TryValidateObject : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> -> bool
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Constructing a ValidationContext without a display name is not trim-safe because it uses reflection to discover the type of the instance being validated in order to resolve the DisplayNameAttribute when a display name is not provided.")>]
static member TryValidateObject : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> -> bool
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")>]
static member TryValidateObject : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> -> bool
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")>]
static member TryValidateObject : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> -> bool
Public Shared Function TryValidateObject (instance As Object, validationContext As ValidationContext, validationResults As ICollection(Of ValidationResult)) As Boolean

Paraméterek

instance
Object

Az érvényesítendő objektum.

validationContext
ValidationContext

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

validationResults
ICollection<ValidationResult>

Egy gyűjtemény, amely az egyes sikertelen érvényesítéseket tárolja.

Válaszok

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

Attribútumok

Kivételek

instance az null.

instance nem egyezik a ObjectInstancebekapcsolva validationContext.

Megjegyzések

Ez a metódus kiértékeli az objektumtípushoz csatolt példányokat ValidationAttribute . Azt is ellenőrzi, hogy minden egyes megjelölt tulajdonság meg van-e adva RequiredAttribute . Nem ellenőrzi rekurzívan az objektum tulajdonságértékeit.

A következőre érvényes:

TryValidateObject(Object, ValidationContext, ICollection<ValidationResult>, Boolean)

Forrás:
Validator.cs
Forrás:
Validator.cs
Forrás:
Validator.cs
Forrás:
Validator.cs
Forrás:
Validator.cs

Meghatározza, hogy a megadott objektum érvényes-e az érvényesítési környezet, az érvényesítési eredmények gyűjteményének és egy olyan értéknek a használatával, amely meghatározza, hogy az összes tulajdonság érvényesíthető-e.

public:
 static bool TryValidateObject(System::Object ^ instance, System::ComponentModel::DataAnnotations::ValidationContext ^ validationContext, System::Collections::Generic::ICollection<System::ComponentModel::DataAnnotations::ValidationResult ^> ^ validationResults, bool validateAllProperties);
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> validationResults, bool validateAllProperties);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Constructing a ValidationContext without a display name is not trim-safe because it uses reflection to discover the type of the instance being validated in order to resolve the DisplayNameAttribute when a display name is not provided.")]
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults, bool validateAllProperties);
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults, bool validateAllProperties);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")]
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults, bool validateAllProperties);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults, bool validateAllProperties);
static member TryValidateObject : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> * bool -> bool
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Constructing a ValidationContext without a display name is not trim-safe because it uses reflection to discover the type of the instance being validated in order to resolve the DisplayNameAttribute when a display name is not provided.")>]
static member TryValidateObject : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> * bool -> bool
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")>]
static member TryValidateObject : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> * bool -> bool
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")>]
static member TryValidateObject : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> * bool -> bool
Public Shared Function TryValidateObject (instance As Object, validationContext As ValidationContext, validationResults As ICollection(Of ValidationResult), validateAllProperties As Boolean) As Boolean

Paraméterek

instance
Object

Az érvényesítendő objektum.

validationContext
ValidationContext

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

validationResults
ICollection<ValidationResult>

Egy gyűjtemény, amely az egyes sikertelen érvényesítéseket tárolja.

validateAllProperties
Boolean

true az összes tulajdonság ellenőrzése; ha false, csak a szükséges attribútumok vannak érvényesítve.

Válaszok

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

Attribútumok

Kivételek

instance az null.

instance nem egyezik aObjectInstancebekapcsolva validationContext.

Megjegyzések

Ez a metódus kiértékeli az objektumtípushoz csatolt példányokat ValidationAttribute . Azt is ellenőrzi, hogy minden egyes megjelölt tulajdonság meg van-e adva RequiredAttribute . Ellenőrzi az objektum tulajdonságértékeit, ha validateAllProperties igen, true de nem rekurzívan ellenőrzi a tulajdonságok által visszaadott objektumok tulajdonságait.

A következőre érvényes: