コード例 #1
0
ファイル: SiegeProxy.cs プロジェクト: ot-nara-alzapur/Siege
        private GeneratedVariable GenerateEncapsulatedCalls(MethodInfo methodInfo, MethodBodyContext body, GeneratedVariable serviceLocator, GeneratedField field)
        {
            var attributes = methodInfo.GetCustomAttributes(typeof(IProcessEncapsulatingAttribute), true);

            GeneratedVariable variable = null;

            if (attributes.Length == 0)
            {
                if (methodInfo.ReturnType == typeof(void))
                {
                    body.CallBase(methodInfo);
                }
                else
                {
                    variable = body.CreateVariable(methodInfo.ReturnType);
                    variable.AssignFrom(() => body.CallBase(methodInfo));
                }

                return(variable);
            }

            var encapsulating = body.CreateVariable <IProcessEncapsulatingAttribute>();

            if (useServiceLocator)
            {
                encapsulating.AssignFrom(() => serviceLocator.Invoke(typeof(Microsoft.Practices.ServiceLocation.IServiceLocator).GetMethod("GetInstance", new Type[0]).MakeGenericMethod(attributes[0].GetType())));
            }
            else
            {
                encapsulating.AssignFrom(body.Instantiate(attributes[0].GetType()));
            }
            MethodInfo target         = null;
            var        lambdaVariable = body.CreateLambda(lambda =>
            {
                target = lambda.Target(methodInfo);

                RecursivelyGenerateCalls(attributes, 1, lambda, methodInfo, field);
            });

            var func = lambdaVariable.CreateFunc(target);

            if (methodInfo.ReturnType != typeof(void))
            {
                variable = body.CreateVariable(methodInfo.ReturnType);
                new DefaultProcessEncapsulatingInterceptionStrategy().Intercept(methodInfo, attributes[0], func, variable, encapsulating);
            }
            else
            {
                new DefaultProcessEncapsulatingActionInterceptionStrategy().Intercept(methodInfo, attributes[0], func, null, encapsulating);
            }

            return(variable);
        }
コード例 #2
0
ファイル: SiegeProxy.cs プロジェクト: ot-nara-alzapur/Siege
        private void GeneratePostProcessors(MethodBodyContext body, ICustomAttributeProvider methodInfo, GeneratedVariable serviceLocator)
        {
            var attributes = methodInfo.GetCustomAttributes(typeof(IPostProcessingAttribute), true);

            for (int i = 0; i < attributes.Length; i++)
            {
                var attribute     = attributes[i];
                var postProcessor = body.CreateVariable <IPostProcessingAttribute>();
                if (useServiceLocator)
                {
                    postProcessor.AssignFrom(() => serviceLocator.Invoke(typeof(Microsoft.Practices.ServiceLocation.IServiceLocator).GetMethod("GetInstance", new Type[0]).MakeGenericMethod(attribute.GetType())));
                }
                else
                {
                    postProcessor.AssignFrom(body.Instantiate(attribute.GetType()));
                }

                postProcessor.Invoke <IDefaultPostProcessingAttribute>(processor => processor.Process());
            }
        }