예제 #1
0
        /// <summary>
        /// 执行方法
        /// </summary>
        /// <param name="extraArgs"></param>
        /// <exception cref="InvalidOperationException">实例不存在</exception>
        /// <exception cref="TargetInvocationException">方法执行时抛出异常</exception>
        /// <returns></returns>
        public object Invoke(Dictionary <string, object> extraArgs = null)
        {
            if (instance == null)
            {
                throw new InvalidOperationException("Please create instance before invoke method");
            }

            object[] args = ParameterArrayBuilder.BuildArgs(
                source,
                extraArgs ?? new Dictionary <string, object>(),
                method.GetParameters());

            object rawInvoker() => method.Invoke(instance, args);

            var aspects = GetAroundAspects();

            if (aspects.Any())
            {
                var aspectArgs = new AroundMethodArgs()
                {
                    MethodInfo = method,
                    Instance   = instance,
                    Args       = args,
                    ExtraArgs  = extraArgs,
                    Invoker    = rawInvoker
                };
                return(aspects.ElementAt(0).Around(aspectArgs));
            }
            else
            {
                return(rawInvoker());
            }
        }
예제 #2
0
 /// <summary>
 /// 执行环绕的函数
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 public abstract object Around(AroundMethodArgs args);