Language

AsyncValidationAttribute.IsValidAsync Method

Definition

Override this method in subclasses to implement asynchronous validation logic.

protected:
 abstract System::Threading::Tasks::Task<System::ComponentModel::DataAnnotations::ValidationResult ^> ^ IsValidAsync(System::Object ^ value, System::ComponentModel::DataAnnotations::ValidationContext ^ validationContext, System::Threading::CancellationToken cancellationToken);
protected abstract System.Threading.Tasks.Task<System.ComponentModel.DataAnnotations.ValidationResult?> IsValidAsync(object? value, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Threading.CancellationToken cancellationToken);
abstract member IsValidAsync : obj * System.ComponentModel.DataAnnotations.ValidationContext * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.ComponentModel.DataAnnotations.ValidationResult>
Protected MustOverride Function IsValidAsync (value As Object, validationContext As ValidationContext, cancellationToken As CancellationToken) 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.

Remarks

This method must perform all applicable checks, including checks that can run synchronously. The synchronous IsValid(Object, ValidationContext) implementation is not automatically invoked before this method. Share common checks through a helper when needed.

Implementations must observe the supplied cancellationToken and stop work promptly when cancellation is requested. The validation infrastructure might cancel this token after a validation failure to stop sibling validators and awaits all started validation tasks before returning. An implementation that ignores cancellation can delay failure and short-circuiting.

Applies to