AsyncValidationAttribute.IsValid 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.
Overloads
| Name | Description |
|---|---|
| IsValid(Object) |
Sealed override of IsValid(Object) that delegates to the ValidationContext overload so that AsyncValidationAttribute implementations only need to provide a single synchronous fallback via IsValid(Object, ValidationContext). |
| IsValid(Object, ValidationContext) |
Defines the synchronous validation behavior for this attribute. |
IsValid(Object)
- Source:
- AsyncValidationAttribute.cs
Sealed override of IsValid(Object) that delegates to the ValidationContext overload so that AsyncValidationAttribute implementations only need to provide a single synchronous fallback via IsValid(Object, ValidationContext).
public:
override bool IsValid(System::Object ^ value);
public override sealed bool IsValid(object? value);
override this.IsValid : obj -> bool
Public Overrides NotOverridable Function IsValid (value As Object) As Boolean
Parameters
- value
- Object
The value to validate.
Returns
true if the value is valid; otherwise, false.
Applies to
IsValid(Object, ValidationContext)
- Source:
- AsyncValidationAttribute.cs
Defines the synchronous validation behavior for this attribute.
protected:
abstract System::ComponentModel::DataAnnotations::ValidationResult ^ IsValid(System::Object ^ value, System::ComponentModel::DataAnnotations::ValidationContext ^ validationContext);
protected abstract System.ComponentModel.DataAnnotations.ValidationResult? IsValid(object? value, System.ComponentModel.DataAnnotations.ValidationContext validationContext);
override this.IsValid : obj * System.ComponentModel.DataAnnotations.ValidationContext -> System.ComponentModel.DataAnnotations.ValidationResult
Protected MustOverride Function IsValid (value As Object, validationContext As ValidationContext) As 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. This value can be null when the contextless IsValid(Object) overload invokes this method.
Returns
Success when validation is valid.
An instance of ValidationResult when validation is invalid.
Remarks
Synchronous validation consumers invoke this method. Provide a synchronous implementation when it can evaluate the applicable rule, and return a validation error when the rule rejects the value. If a required rule applies but cannot be evaluated synchronously, throw InvalidOperationException with a message directing callers to an asynchronous validation entry point. An unsupported invocation does not establish that the value is invalid.
Return Success without evaluating the rule only when the rule does not apply. Do not return success merely because a required asynchronous check applies but cannot run synchronously. Success does not indicate pending validation or arrange a later asynchronous invocation.
Do not implement this method by blocking on asynchronous work through Task<TResult>.Result, Task.Wait(), or GetAwaiter().GetResult(). Wrapping the asynchronous operation in Task.Run does not make a blocking wait appropriate.