public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var valueValidatorPair = TypeToValidate != null ? ValidateAttributeCommon.GetValueValidatorExplicitly(context, ValidatorType, TypeToValidate) : ValidateAttributeCommon.GetValueValidatorImplicitly(context, ValidatorType); var validationMethod = valueValidatorPair.Validator.GetType().GetMethod("Validate"); var validationTask = (Task <ValidationResult>)validationMethod?.Invoke( valueValidatorPair.Validator, new[] { valueValidatorPair.Value }); if (validationTask == null) { throw new InvalidOperationException(nameof(validationTask)); } var validationResult = await validationTask; if (validationResult.Succeeded) { await base.OnActionExecutionAsync(context, next); return; } context.Result = new BadRequestObjectResult(validationResult); }
public override Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var valueValidatorPair = TypeToValidate != null ? ValidateAttributeCommon.GetValueValidatorExplicitly(context, ValidatorType, TypeToValidate) : ValidateAttributeCommon.GetValueValidatorImplicitly(context, ValidatorType); var validationMethod = valueValidatorPair.Validator.GetType().GetMethod("Validate"); var validationResult = (ValidationResult)validationMethod?.Invoke( valueValidatorPair.Validator, new[] { valueValidatorPair.Value }); if (validationResult.Succeeded) { return(base.OnActionExecutionAsync(context, next)); } context.Result = new BadRequestObjectResult(validationResult); return(Task.CompletedTask); }