Validator.TryValidateValueAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Asynchronously tests whether the given value is valid against a specified list of ValidationAttributes.
public static System.Threading.Tasks.Task<bool> TryValidateValueAsync(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, System.Threading.CancellationToken cancellationToken = default);
static member TryValidateValueAsync : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> * seq<System.ComponentModel.DataAnnotations.ValidationAttribute> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<bool>
Public Shared Function TryValidateValueAsync (value As Object, validationContext As ValidationContext, validationResults As ICollection(Of ValidationResult), validationAttributes As IEnumerable(Of ValidationAttribute), Optional cancellationToken As CancellationToken = Nothing) As Task(Of Boolean)
Parameters
- value
- Object
The value to test.
- validationContext
- ValidationContext
Describes the object being validated and provides services and context for the validators.
- validationResults
- ICollection<ValidationResult>
An optional collection that receives validation failures as ValidationResult instances.
- validationAttributes
- IEnumerable<ValidationAttribute>
The list of ValidationAttributes to validate this value against.
- cancellationToken
- CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Returns
A Task<TResult> that is true if the value is valid, false if any validation errors are encountered.
Exceptions
When validationContext is null.
When validationAttributes is null.
The validation operation was canceled.
Remarks
This method tests each specified ValidationAttribute. If validationResults is non-null, this method adds a ValidationResult to it for each validation failure.
Any AsyncValidationAttribute instances are evaluated asynchronously after all synchronous validation attributes have passed.