Ejemplo n.º 1
0
        /// <summary>
        ///   获取目标函数
        /// </summary>
        /// <param name="aopAttributeMethodInfoProxyCategory"></param>
        /// <param name="aopMethodType"></param>
        /// <param name="sourceMethodOwner"></param>
        /// <param name="sourceMethodBase"></param>
        /// <param name="sourceMethodParameterTypes"></param>
        /// <returns></returns>
        private MethodInfoProxy GetTargetMethodInfoProxy(
            AOPAttributeMethodInfoProxyCategory aopAttributeMethodInfoProxyCategory,
            AOPMethodType aopMethodType, object sourceMethodOwner, MethodBase sourceMethodBase,
            params Type[] sourceMethodParameterTypes)
        {
            //如果缓存中有对应的aop处理函数,则不用查找,直接使用
            if (aopAttributeMethodInfoProxyCategory.aopMethodInfoDict.ContainsKey(aopMethodType))
            {
                return(aopAttributeMethodInfoProxyCategory.aopMethodInfoDict[aopMethodType]);
            }

            //根据优先顺序查找
            var aopAttributeType = aopAttributeMethodInfoProxyCategory.aopAttribute.GetType();
            var sourceMethodName = sourceMethodBase.Name;

            return(AOPUtil.SeachTargetMethodInfoProxy(aopAttributeType, sourceMethodBase.DeclaringType,
                                                      sourceMethodName,
                                                      aopMethodType, sourceMethodParameterTypes));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   查找并调用被切面的方法的其中一个AOPAttribute属性中的AOP处理方法
        /// </summary>
        /// <param name="aopAttributeMethodInfoProxyCategory"></param>
        /// <param name="aopMethodType"></param>
        /// <param name="sourceMethodOwner"></param>
        /// <param name="sourceMethodBase"></param>
        /// <param name="sourceMethodArgs"></param>
        private void InvokeAOPAttributeMethod(AOPAttributeMethodInfoProxyCategory aopAttributeMethodInfoProxyCategory,
                                              AOPMethodType aopMethodType, object sourceMethodOwner, MethodBase sourceMethodBase,
                                              params object[] sourceMethodArgs)
        {
            //获取目标函数
            var targetMethodInfoProxy = GetTargetMethodInfoProxy(aopAttributeMethodInfoProxyCategory, aopMethodType,
                                                                 sourceMethodOwner, sourceMethodBase, sourceMethodBase.GetParameterTypes());

            //缓存目标函数以备下次使用
            aopAttributeMethodInfoProxyCategory.aopMethodInfoDict[aopMethodType] = targetMethodInfoProxy;

            //调用目标函数
            var targetMethodInfo = targetMethodInfoProxy.GetTargetMethodInfo();
            var targetMethodArgs = GetTargetMethodArgs(targetMethodInfoProxy.isTargetMethodAddSelfArg,
                                                       sourceMethodOwner,
                                                       targetMethodInfoProxy.isTargetMethodWithSourceArgs, sourceMethodArgs);

            targetMethodInfo.Invoke(aopAttributeMethodInfoProxyCategory.aopAttribute, targetMethodArgs);
        }