private async Task InvokePropertyValidatorAsync(ValidationContext <T> context, Lazy <TProperty> accessor, string propertyName, RuleComponent <T, TProperty> component, CancellationToken cancellation) { if (!component.InvokeCondition(context)) { return; } if (!await component.InvokeAsyncCondition(context, cancellation)) { return; } bool valid = await component.ValidateAsync(context, accessor.Value, cancellation); if (!valid) { PrepareMessageFormatterForValidationError(context, accessor.Value); var failure = CreateValidationError(context, accessor.Value, component); component.OnFailure?.Invoke(context.InstanceToValidate, context, accessor.Value, failure.ErrorMessage); context.Failures.Add(failure); } }
private protected void InvokePropertyValidator(ValidationContext <T> context, Lazy <TProperty> accessor, string propertyName, RuleComponent <T, TProperty> component) { if (!component.InvokeCondition(context)) { return; } if (component.HasAsyncCondition && !component.InvokeAsyncCondition(context, CancellationToken.None).GetAwaiter().GetResult()) { return; } bool valid = component.Validate(context, accessor.Value); if (!valid) { PrepareMessageFormatterForValidationError(context, accessor.Value); var failure = CreateValidationError(context, accessor.Value, component); component.OnFailure?.Invoke(context.InstanceToValidate, context, accessor.Value, failure.ErrorMessage); context.Failures.Add(failure); } }