コード例 #1
0
        private async Task InvokePropertyValidatorAsync(ValidationContext <T> context, Lazy <TProperty> accessor, string propertyName, RuleComponent <T, TProperty> component, CancellationToken cancellation)
        {
            bool valid = await component.ValidateAsync(context, accessor.Value, cancellation);

            if (!valid)
            {
                PrepareMessageFormatterForValidationError(context, accessor.Value);
                var failure = CreateValidationError(context, accessor.Value, component);
                context.Failures.Add(failure);
            }
        }
コード例 #2
0
        private async Task InvokePropertyValidatorAsync(ValidationContext <T> context, TElement value, string propertyName, RuleComponent <T, TElement> component, int index, CancellationToken cancellation)
        {
            context.MessageFormatter.AppendArgument("CollectionIndex", index);
            bool valid = await component.ValidateAsync(context, value, cancellation);

            if (!valid)
            {
                PrepareMessageFormatterForValidationError(context, value);
                var failure = CreateValidationError(context, value, component);
                context.Failures.Add(failure);
            }
        }
コード例 #3
0
        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);
            }
        }