MethodInterceptor

目录

1 MethodInterceptor

1.1 HandleSync

1.2 HandleException

1.3 /// This will be called via Reflection

  1. MethodInterceptor
    1. HandleSync

        private void HandleSync(IReadOnlyList filterAttributes, IReadOnlyList exceptionFilterAttributes, MethodExecutingContext methodExecutingContext)

        {

            foreach (var f in filterAttributes)

            {

                try

                {

                    if (methodExecutingContext.Result == null) f.OnMethodExecuting(methodExecutingContext);

                }

                catch (Exception ex)

                {

                var exContext = new MethodExceptionContext(ex, methodExecutingContext);

HandleException(exceptionFilterAttributes, exContext);

                if (!exContext.Handled)

                {

throw;

                }

                }

            }

            var reversedFilterAttributes = filterAttributes.Reverse();

            var methodExecutedContext = new MethodExecutedContext(methodExecutingContext);

            foreach (var f in reversedFilterAttributes)

            {

                try

                {

                    f.OnMethodExecuted(methodExecutedContext);

                }

                catch (Exception ex)

                {

                var exContext = new MethodExceptionContext(ex, methodExecutedContext);

                HandleException(exceptionFilterAttributes, exContext);

                if (!exContext.Handled)

                {

                throw;

                }

                }

            }

        }

    1.         HandleException

        private void HandleException(IReadOnlyList exceptionFilterAttributes, MethodExceptionContext exceptionContext)

        {

            foreach (var f in exceptionFilterAttributes)

            {

                try

                {

                    if (!exceptionContext.Handled)

                    {

                        f.OnException(exceptionContext);

                    }

                }

                catch (Exception ex)

                {

                    throw new AggregateException(ex.Message, ex, exceptionContext.Exception);

                }

            }

        }

    ///

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