Validator.TryValidateObject Metod

Definition

Avgör om det angivna objektet är giltigt.

Överlagringar

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

Avgör om det angivna objektet är giltigt med hjälp av verifieringskontexten och verifieringsresultatsamlingen.

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

Avgör om det angivna objektet är giltigt med hjälp av valideringskontexten, verifieringsresultatsamlingen och ett värde som anger om alla egenskaper ska verifieras.

TryValidateObject(Object, ValidationContext, ICollection<ValidationResult>)

Källa:
Validator.cs
Källa:
Validator.cs
Källa:
Validator.cs
Källa:
Validator.cs
Källa:
Validator.cs

Avgör om det angivna objektet är giltigt med hjälp av verifieringskontexten och verifieringsresultatsamlingen.

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

Parametrar

instance
Object

Objektet som ska verifieras.

validationContext
ValidationContext

Kontexten som beskriver objektet som ska verifieras.

validationResults
ICollection<ValidationResult>

En samling för att lagra varje misslyckad validering.

Returer

trueom objektet verifierar; annars . false

Attribut

Undantag

instance är null.

instancematchar inte på ObjectInstancevalidationContext.

Kommentarer

Den här metoden utvärderar varje ValidationAttribute instans som är kopplad till objekttypen. Den kontrollerar också om varje egenskap som är markerad med RequiredAttribute har angetts. Det validerar inte objektets egenskapsvärden rekursivt.

Gäller för

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

Källa:
Validator.cs
Källa:
Validator.cs
Källa:
Validator.cs
Källa:
Validator.cs
Källa:
Validator.cs

Avgör om det angivna objektet är giltigt med hjälp av valideringskontexten, verifieringsresultatsamlingen och ett värde som anger om alla egenskaper ska verifieras.

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

Parametrar

instance
Object

Objektet som ska verifieras.

validationContext
ValidationContext

Kontexten som beskriver objektet som ska verifieras.

validationResults
ICollection<ValidationResult>

En samling för att lagra varje misslyckad validering.

validateAllProperties
Boolean

true för att verifiera alla egenskaper. om falseverifieras endast obligatoriska attribut.

Returer

trueom objektet verifierar; annars . false

Attribut

Undantag

instance är null.

instancematchar inte påObjectInstancevalidationContext .

Kommentarer

Den här metoden utvärderar varje ValidationAttribute instans som är kopplad till objekttypen. Den kontrollerar också om varje egenskap som är markerad med RequiredAttribute har angetts. Det verifierar egenskapsvärdena för objektet om validateAllProperties det är true men validerar inte rekursivt egenskaperna för de objekt som returneras av egenskaperna.

Gäller för