AsyncValidationAttribute.GetValidationResultAsync 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.
Tests whether the given value is valid asynchronously with respect to the current validation attribute without throwing a ValidationException.
public System.Threading.Tasks.Task<System.ComponentModel.DataAnnotations.ValidationResult?> GetValidationResultAsync(object? value, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Threading.CancellationToken cancellationToken = default);
member this.GetValidationResultAsync : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.ComponentModel.DataAnnotations.ValidationResult>
Public Function GetValidationResultAsync (value As Object, validationContext As ValidationContext, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ValidationResult)
Parameters
- value
- Object
The value to validate.
- validationContext
- ValidationContext
A ValidationContext instance that provides context about the validation operation, such as the object and member being validated. Provides access to services required to perform validation using IServiceProvider.
- cancellationToken
- CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Returns
A Task<TResult> representing the asynchronous validation operation.
When validation is valid, the result is Success.
When validation is invalid, the result is an instance of ValidationResult.
Exceptions
The current attribute is malformed.
When validationContext is null.
The validation operation was canceled.
Remarks
The underlying IsValidAsync(Object, ValidationContext, CancellationToken) implementation must observe the supplied cancellationToken and stop work promptly when cancellation is requested. The validation infrastructure awaits all started validation tasks before returning, so an implementation that ignores cancellation can delay failure and short-circuiting.
Callers that need to bound validation time should pass a token configured to cancel after a timeout, such as one from a CancellationTokenSource configured with CancelAfter(TimeSpan).