Example #1
0
 /// <summary>
 /// 下一步操作
 /// </summary>
 /// <param name="methodInvoke"></param>
 /// <param name="then"></param>
 /// <returns></returns>
 private Func <object> NextWrapper(IMethodInvoke methodInvoke, Func <object> then)
 {
     return(() =>
     {
         return WhileToCanCall(methodInvoke, then);
     });
 }
 /// <summary>
 /// Initializes the <see cref="AroundInvokeAdapter"/> class.
 /// </summary>
 /// <param name="getTarget">The functor responsible for obtaining the target instance.</param>
 /// <param name="methodInvoke">The method invoker.</param>
 /// <param name="aroundInvoke">The target <see cref="IAroundInvoke"/> instance.</param>
 internal AroundInvokeAdapter(Func<object> getTarget, IMethodInvoke<MethodInfo> methodInvoke,
                              IAroundInvoke aroundInvoke)
     : base(methodInvoke)
 {
     _wrapper = aroundInvoke;
     _getTarget = getTarget;
 }
Example #3
0
 /// <summary>
 ///     Initializes the <see cref="AroundInvokeAdapter" /> class.
 /// </summary>
 /// <param name="getTarget">The functor responsible for obtaining the target instance.</param>
 /// <param name="methodInvoke">The method invoker.</param>
 /// <param name="aroundInvoke">The target <see cref="IAroundInvoke" /> instance.</param>
 internal AroundInvokeAdapter(Func <object> getTarget, IMethodInvoke <MethodInfo> methodInvoke,
                              IAroundInvoke aroundInvoke)
     : base(methodInvoke)
 {
     _wrapper   = aroundInvoke;
     _getTarget = getTarget;
 }
 /// <summary>
 /// Initializes the class with a functor that can provide the actual target instance.
 /// </summary>
 /// <param name="getActualTarget">The <see cref="Func{TResult}"/> that will provide the target instance that will be used for the method invocation.</param>
 /// <param name="methodInvoke">The method invoker.</param>
 /// <param name="realInfo">The <see cref="IInvocationInfo"/> instance that describes the current execution context.</param>
 internal InvocationInfoInterceptor(IInvocationInfo realInfo, Func<object> getActualTarget,
                                    IMethodInvoke<MethodInfo> methodInvoke)
     : base(methodInvoke)
 {
     _getActualTarget = getActualTarget;
     _realInfo = realInfo;
 }
Example #5
0
 public Redirector(Func <object> getActualTarget, IInterceptor targetInterceptor, IProxyFactory factory,
                   IMethodInvoke <MethodInfo> methodInvoke)
     : base(methodInvoke)
 {
     _getActualTarget = getActualTarget;
     _interceptor     = targetInterceptor;
     _proxyFactory    = factory;
 }
Example #6
0
            /// <summary>
            /// 拦截器
            /// </summary>
            /// <param name="methodInvoke"></param>
            /// <param name="next"></param>
            /// <returns></returns>
            public object Interception(IMethodInvoke methodInvoke, Func <object> next)
            {
                Debug.Log("befor intercepting");
                var ret = next();

                Debug.Log("after intercepting");
                return(ret);
            }
Example #7
0
 public Redirector(Func<object> getActualTarget, IInterceptor targetInterceptor, IProxyFactory factory,
     IMethodInvoke<MethodInfo> methodInvoke)
     : base(methodInvoke)
 {
     _getActualTarget = getActualTarget;
     _interceptor = targetInterceptor;
     _proxyFactory = factory;
 }
Example #8
0
        /// <summary>
        /// 执行管道
        /// </summary>
        /// <param name="methodInvoke"></param>
        /// <param name="then"></param>
        /// <returns></returns>
        public object Do(IMethodInvoke methodInvoke, Func <object> then)
        {
            if (interceptionBehaviors.Count <= 0)
            {
                return(then.Invoke());
            }

            stack.Push(-1);

            object ret = WhileToCanCall(methodInvoke, then);

            stack.Pop();

            return(ret);
        }
Example #9
0
        /// <summary>
        /// 是否是生效的
        /// </summary>
        /// <param name="interception"></param>
        /// <returns></returns>
        private bool IsEnable(IMethodInvoke methodInvoke, IInterception interception)
        {
            if (!interception.Enable)
            {
                return(false);
            }

            foreach (var ret in interception.GetRequiredAttr())
            {
                if (!methodInvoke.MethodBase.IsDefined(ret, false))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #10
0
        /// <summary>
        /// 循环到第一个可以调用的拦截器并调用
        /// </summary>
        /// <param name="methodInvoke"></param>
        /// <param name="then"></param>
        /// <returns></returns>
        private object WhileToCanCall(IMethodInvoke methodInvoke, Func <object> then)
        {
            int index = 0;

            do
            {
                index = stack.Pop();
                stack.Push(++index);

                if (index >= interceptionBehaviors.Count)
                {
                    return(then.Invoke());
                }
            } while (!IsEnable(methodInvoke, interceptionBehaviors[index]));

            return(interceptionBehaviors[index].Interception(methodInvoke, NextWrapper(methodInvoke, then)));
        }
Example #11
0
 /// <summary>
 /// 拦截器方案
 /// </summary>
 /// <param name="methodInvoke">方法调用</param>
 /// <param name="next">下一个拦截器</param>
 /// <returns>拦截返回值</returns>
 public object Interception(IMethodInvoke methodInvoke, Func <object> next)
 {
     return(next());
 }
Example #12
0
 /// <summary>
 ///     Initializes the class with the <paramref name="methodInvoke" /> instance.
 /// </summary>
 /// <param name="methodInvoke">The <see cref="IMethodInvoke{TMethod}" /> instance that will invoke the target method.</param>
 protected BaseInterceptor(IMethodInvoke <MethodInfo> methodInvoke)
 {
     MethodInvoker = methodInvoke;
 }
Example #13
0
 /// <summary>
 /// Initializes the class with the default services.
 /// </summary>
 /// <param name="container">The target service container.</param>
 public void Initialize(IServiceContainer container)
 {
     _resolver          = container.GetService <IMemberResolver <ConstructorInfo> >();
     _constructorInvoke = container.GetService <IMethodInvoke <ConstructorInfo> >();
     _argumentResolver  = container.GetService <IConstructorArgumentResolver>();
 }
Example #14
0
 /// <summary>
 /// Initializes the class with a functor that can provide the actual target instance.
 /// </summary>
 /// <param name="getActualTarget">The <see cref="Func{TResult}"/> that will provide the target instance that will be used for the method invocation.</param>
 /// <param name="methodInvoke">The method invoker.</param>
 /// <param name="realInfo">The <see cref="IInvocationInfo"/> instance that describes the current execution context.</param>
 internal InvocationInfoInterceptor(IInvocationInfo realInfo, Func <object> getActualTarget,
                                    IMethodInvoke <MethodInfo> methodInvoke) : base(methodInvoke)
 {
     _getActualTarget = getActualTarget;
     _realInfo        = realInfo;
 }
 /// <summary>
 /// The default constructor.
 /// </summary>
 protected BaseInterceptor()
 {
     _methodInvoke = new MethodInvoke();
 }
Example #16
0
 /// <summary>
 /// The default constructor.
 /// </summary>
 protected BaseInterceptor()
 {
     _methodInvoke = new MethodInvoke();
 }
 /// <summary>
 /// Initializes the class with the <paramref name="methodInvoke"/> instance.
 /// </summary>
 /// <param name="methodInvoke">The <see cref="IMethodInvoke{TMethod}"/> instance that will invoke the target method.</param>
 protected BaseInterceptor(IMethodInvoke<MethodInfo> methodInvoke)
 {
     _methodInvoke = methodInvoke;
 }