Class ValidationRule<T>
Validation rule which uses a Rule function (sync or async) to evaluate
public sealed class ValidationRule<T> : IValidationRule where T : IHasChanges
Type Parameters
TThe type of the value of the field being validated
- Inheritance
-
ValidationRule<T>
- Implements
- Inherited Members
Constructors
ValidationRule(AsyncRule<T>, ValidationScope?)
public ValidationRule(AsyncRule<T> rule, ValidationScope? scope = null)
Parameters
ruleAsyncRule<T>scopeValidationScope
ValidationRule(Rule<T>, ValidationScope?)
public ValidationRule(Rule<T> rule, ValidationScope? scope = null)
Parameters
ruleRule<T>scopeValidationScope
Properties
IsAsyncRule
public bool IsAsyncRule { get; }
Property Value
Scope
public ValidationScope Scope { get; }
Property Value
Methods
Evaluate(IValidatable)
Evaluates the validation rule (synchronously) and returns the result (including result type and message)
public ValidationResult Evaluate(IValidatable subject)
Parameters
subjectIValidatableThe field being validated using this rule
Returns
- ValidationResult
ValidationResult
Exceptions
- InvalidOperationException
If this rule is an async rule, an InvalidOperationException will be thrown.
- ArgumentException
If the subject argument provided is not an IValidatable of the expected type, an ArgumentException will be thrown
EvaluateAsync(IValidatable)
Evaluates the validation rule (asynchronously) and returns the result (including result type and message)
public Task<ValidationResult> EvaluateAsync(IValidatable subject)
Parameters
subjectIValidatableThe field being validated using this rule
Returns
- Task<ValidationResult>
ValidationResult
Remarks
A synchronous rule may be evaluated using EvaluateAsync, but it will be evaluated synchronously
Exceptions
- ArgumentException
If the subject argument provided is not an IValidatable of the expected type, an ArgumentException will be thrown