/// <summary> /// The invoke. /// </summary> /// <param name="input"> /// The input. /// </param> /// <param name="getNext"> /// The get next. /// </param> /// <returns> /// The <see cref="IMethodReturn"/>. /// </returns> public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext) { // Before invoking the method on the original target. var list = new List <object>(); foreach (var argument in input.Arguments) { list.Add(argument); } var group = new MethodInvocationValidator(input.MethodBase, list.ToArray()); group.Validate(); // Invoke the next behavior in the chain. var result = getNext()(input, getNext); // After invoking the method on the original target. return(result); }
public override void OnActionExecuting(ActionExecutingContext context) { var action = context.ActionDescriptor as ControllerActionDescriptor; var method = action.MethodInfo; var arguments = context.ActionArguments.Values.ToArray(); _logger.LogInformation($"开启验证:{method.Name}"); var failures = _validator.Validate(method, arguments); if (failures.Any()) { _logger.LogInformation($"验证失败:{method.Name} {failures.Select(o => o.ToString()).ToJoin()}"); context.Result = new JsonResult(new AjaxResult() { Type = Enums.AjaxResultType.Error, Message = failures.Select(o => o.ToString()).ToJoin() }); return; } _logger.LogInformation($"验证成功:{method.Name}"); }