MethodInterceptor

目录

1 MethodInterceptor

1.1 /// This will be called via Reflection

1.2 HandleAsync

  1. MethodInterceptor
    1.     /// This will be called via Reflection

    ///

    ///

    ///

    ///

    ///

    ///

    private async Task HandleAsyncWithType(IReadOnlyList filterAttributes, IReadOnlyList exceptionFilterAttributes, MethodExecutingContext methodExecutingContext)

        {

        foreach (var f in filterAttributes)

        {

        try

        {

        if (methodExecutingContext.Result == null) await f.OnMethodExecutingAsync(methodExecutingContext).ConfigureAwait(false);

        }

        catch (Exception ex)

        {

        var exContext = new MethodExceptionContext(ex, methodExecutingContext);

        await HandleExceptionAsync(exceptionFilterAttributes, exContext);

        if (!exContext.Handled)

        {

        throw;

        }

        }

        }

        var reversedFilterAttributes = filterAttributes.Reverse();

        var methodExecutedContext = new MethodExecutedContext(methodExecutingContext);

        foreach (var f in reversedFilterAttributes)

        {

        try

        {

        await f.OnMethodExecutedAsync(methodExecutedContext).ConfigureAwait(false);

        }

        catch (Exception ex)

        {

        var exContext = new MethodExceptionContext(ex, methodExecutedContext);

        await HandleExceptionAsync(exceptionFilterAttributes, exContext);

        if (!exContext.Handled)

        {

        throw;

        }

        }

        }

        if (methodExecutedContext.Result != null && methodExecutedContext.Result is TResult result)

        {

        return result;

        }

return default(TResult);

        }

    1. HandleAsync

        private async Task HandleAsync(IReadOnlyList filterAttributes, IReadOnlyList exceptionFilterAttributes, MethodExecutingContext methodExecutingContext)

        {

        foreach (var f in filterAttributes)

        {

        try

        {

        if (methodExecutingContext.Result == null) await f.OnMethodExecutingAsync(methodExecutingContext).ConfigureAwait(false);

        }

        catch (Exception ex)

        {

        var exContext = new MethodExceptionContext(ex, methodExecutingContext);

        await HandleExceptionAsync(exceptionFilterAttributes, exContext);

        if (!exContext.Handled)

        {

        throw;

        }

        }

        }

        var reversedFilterAttributes = filterAttributes.Reverse();

        var methodExecutedContext = new MethodExecutedContext(methodExecutingContext);

        foreach (var f in reversedFilterAttributes)

        {

        try

        {

        await f.OnMethodExecutedAsync(methodExecutedContext).ConfigureAwait(false);

        }

        catch (Exception ex)

        {

        var exContext = new MethodExceptionContext(ex, methodExecutedContext);

        await HandleExceptionAsync(exceptionFilterAttributes, exContext);

        if (!exContext.Handled)

        {

        throw;

        }

        }

        }

        }

你可能感兴趣的:(Flatwhite,java,前端,javascript,Flatwhite)