Validator.TryValidateObject Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Bepaalt of het opgegeven object geldig is.
Overloads
| Name | Description |
|---|---|
| TryValidateObject(Object, ValidationContext, ICollection<ValidationResult>) |
Bepaalt of het opgegeven object geldig is met behulp van de validatiecontext en de verzameling validatieresultaten. |
| TryValidateObject(Object, ValidationContext, ICollection<ValidationResult>, Boolean) |
Bepaalt of het opgegeven object geldig is met behulp van de validatiecontext, de verzameling validatieresultaten en een waarde die aangeeft of alle eigenschappen moeten worden gevalideerd. |
TryValidateObject(Object, ValidationContext, ICollection<ValidationResult>)
- Bron:
- Validator.cs
- Bron:
- Validator.cs
- Bron:
- Validator.cs
- Bron:
- Validator.cs
- Bron:
- Validator.cs
Bepaalt of het opgegeven object geldig is met behulp van de validatiecontext en de verzameling validatieresultaten.
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
Parameters
- instance
- Object
Het object dat moet worden gevalideerd.
- validationContext
- ValidationContext
De context die het object beschrijft dat moet worden gevalideerd.
- validationResults
- ICollection<ValidationResult>
Een verzameling voor elke mislukte validatie.
Retouren
true als het object valideert; anders, false.
- Kenmerken
Uitzonderingen
instance is null.
instance komt niet overeen met de ObjectInstanceon validationContext.
Opmerkingen
Met deze methode wordt elke ValidationAttribute instantie geëvalueerd die is gekoppeld aan het objecttype. Ook wordt gecontroleerd of elke eigenschap die is gemarkeerd RequiredAttribute , is opgegeven. De eigenschapswaarden van het object worden niet recursief gevalideerd.
Van toepassing op
TryValidateObject(Object, ValidationContext, ICollection<ValidationResult>, Boolean)
- Bron:
- Validator.cs
- Bron:
- Validator.cs
- Bron:
- Validator.cs
- Bron:
- Validator.cs
- Bron:
- Validator.cs
Bepaalt of het opgegeven object geldig is met behulp van de validatiecontext, de verzameling validatieresultaten en een waarde die aangeeft of alle eigenschappen moeten worden gevalideerd.
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
Parameters
- instance
- Object
Het object dat moet worden gevalideerd.
- validationContext
- ValidationContext
De context die het object beschrijft dat moet worden gevalideerd.
- validationResults
- ICollection<ValidationResult>
Een verzameling voor elke mislukte validatie.
- validateAllProperties
- Boolean
true om alle eigenschappen te valideren; als falsealleen vereiste kenmerken worden gevalideerd.
Retouren
true als het object valideert; anders, false.
- Kenmerken
Uitzonderingen
instance is null.
instance komt niet overeen met deObjectInstanceon validationContext.
Opmerkingen
Met deze methode wordt elke ValidationAttribute instantie geëvalueerd die is gekoppeld aan het objecttype. Ook wordt gecontroleerd of elke eigenschap die is gemarkeerd RequiredAttribute , is opgegeven. Hiermee worden de eigenschapswaarden van het object gevalideerd, indien validateAllProperties dat wel het geval is true , maar worden eigenschappen van de objecten die door de eigenschappen worden geretourneerd, niet recursief gevalideerd.