Beispiel #1
0
        public object HandleFastCall(IAopProxy target, object executionTarget, int methodIndex, object[] rawParameters, Type returnType)
        {
            CallInfo info = MethodCache.GetCallInfo(methodIndex);

            MethodBase method       = info.Method;
            IList      interceptors = info.Interceptors;

            InterceptedParameter[] parameters = new InterceptedParameter[rawParameters.Length];
            int index = 0;

            foreach (InvocationParameterInfo parameterInfo in info.InvocationParameterInfos)
            {
                InterceptedParameter parameter = new InterceptedParameter(parameterInfo, rawParameters, index);
                parameters[index] = parameter;
                index++;
            }

#if NET2
            MethodInvocation invocation = new MethodInvocation(target, executionTarget, method, method, parameters, rawParameters, returnType, interceptors);
            invocation.Handler = info.Handler;
#else
            MethodInfo       wrapperMethod = (MethodInfo)MethodCache.wrapperMethodLookup[info.MethodId];
            MethodInvocation invocation    = new MethodInvocation(target, executionTarget, method, wrapperMethod, parameters, rawParameters, returnType, interceptors);
#endif

            return(invocation.Proceed());
        }
        private void BuildLookupTables(Type proxyType, IList aspects)
        {
            foreach (string methodId in wrapperMethods)
            {
                MethodInfo wrapperMethod =
                    proxyType.GetMethod(methodId,
                                        BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |
                                        BindingFlags.DeclaredOnly);
                MethodCache.wrapperMethodLookup[methodId] = wrapperMethod;

                MethodBase baseMethod = (MethodBase)MethodCache.methodLookup[methodId];
                //array to return
                IList methodinterceptors = new ArrayList();
                //fetch all aspects from the type-aspect lookup
                foreach (IGenericAspect aspect in aspects)
                {
                    foreach (IPointcut pointcut in aspect.Pointcuts)
                    {
                        if (pointcut.IsMatch(baseMethod))
                        {
                            foreach (object interceptor in pointcut.Interceptors)
                            {
                                methodinterceptors.Add(interceptor);
                            }
                        }
                    }
                }

                MethodCache.methodInterceptorsLookup[methodId] = methodinterceptors;
                CallInfo callInfo = MethodCache.GetCallInfo(methodId);
                callInfo.Interceptors = methodinterceptors;
            }
        }
        public object HandleFastCall(IAopProxy target, object executionTarget, int methodIndex, IList parameters, Type returnType)
        {
            CallInfo info = MethodCache.GetCallInfo(methodIndex);

            MethodBase method       = info.Method;
            IList      interceptors = info.Interceptors;


#if NET2
            MethodInvocation invocation = new MethodInvocation(target, executionTarget, method, method, parameters, returnType, interceptors);
            invocation.Handler = info.Handler;
#else
            MethodInfo       wrapperMethod = (MethodInfo)MethodCache.wrapperMethodLookup[info.MethodId];
            MethodInvocation invocation    = new MethodInvocation(target, executionTarget, method, wrapperMethod, parameters, returnType, interceptors);
#endif

            return(invocation.Proceed());
        }
        private void BuildLookupTables(Type proxyType, IList aspects, IList mixins)
        {
            MethodCache.methodsLookup[proxyType] = wrapperMethods;
            MethodCache.aspectsLookup[proxyType] = aspects;
            MethodCache.mixinsLookup[proxyType]  = mixins;

            foreach (string methodId in wrapperMethods)
            {
                MethodInfo wrapperMethod =
                    proxyType.GetMethod(methodId,
                                        BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |
                                        BindingFlags.DeclaredOnly);
                MethodCache.wrapperMethodLookup[methodId] = wrapperMethod;

                MethodBase baseMethod = (MethodBase)MethodCache.methodLookup[methodId];
                //array to return
                IList methodinterceptors = new ArrayList();
                //fetch all aspects from the type-aspect lookup
                foreach (IAspect aspect in aspects)
                {
                    IGenericAspect tmpAspect;
                    if (aspect is IGenericAspect)
                    {
                        tmpAspect = (IGenericAspect)aspect;
                    }
                    else
                    {
                        tmpAspect = TypedToGenericConverter.Convert((ITypedAspect)aspect);
                    }

                    foreach (IPointcut pointcut in tmpAspect.Pointcuts)
                    {
                        if (pointcut.IsMatch(baseMethod, proxyType))
                        {
                            foreach (object interceptor in pointcut.Interceptors)
                            {
                                methodinterceptors.Add(interceptor);
                            }
                        }
                    }
                }
                foreach (FixedInterceptorAttribute fixedInterceptorAttribute in baseMethod.GetCustomAttributes(typeof(FixedInterceptorAttribute), true))
                {
                    foreach (Type type in fixedInterceptorAttribute.Types)
                    {
                        methodinterceptors.Add(engine.GetFixedInterceptor(type));
                    }
                }
                foreach (FixedInterceptorAttribute fixedInterceptorAttribute in baseMethod.DeclaringType.GetCustomAttributes(typeof(FixedInterceptorAttribute), true))
                {
                    foreach (Type type in fixedInterceptorAttribute.Types)
                    {
                        methodinterceptors.Add(engine.GetFixedInterceptor(type));
                    }
                }

                CheckRequiredMixins(baseMethod, methodinterceptors);

                MethodCache.methodInterceptorsLookup[methodId] = methodinterceptors;
                CallInfo callInfo = MethodCache.GetCallInfo(methodId);
                callInfo.Interceptors = methodinterceptors;
            }
        }