Пример #1
0
        public GeneratedVariable LoadValueAtIndex(Type objectType, MethodBodyContext context, int index)
        {
            var variable = context.CreateVariable(objectType);
            actions.Add(new LoadValueAtIndexAction(method, this, index));
            actions.Add(new VariableAssignmentAction(() => method.MethodBuilder(), variable.LocalIndex));

            return variable;
        }
Пример #2
0
 public override void EnterMethodBody([NotNull] MethodBodyContext context)
 {
     foreach (var blockContext in context.GetRuleContexts <BlockContext>())
     {
         foreach (var rule in blockContext.GetRuleContexts <ParserRuleContext>())
         {
             rule.EnterRule(this);
         }
     }
 }
Пример #3
0
        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);
        }
Пример #4
0
        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());
            }
        }
 public virtual void WithBody(Action<MethodBodyContext> nestedClosure)
 {
     var context = new MethodBodyContext(GeneratedMethod, typeGenerationContext, this);
     nestedClosure(context);
 }
Пример #6
0
 public GeneratedDelegate(MethodBodyContext context, GeneratedMethod method, DelegateGenerator generator)
 {
     this.context = context;
     this.method = method;
     this.generator = generator;
 }
Пример #7
0
 public static MethodBody ToAst(this MethodBodyContext methodBodyContext)
 {
     return(new MethodBody(methodBodyContext.varDeclaration().Select(varDecl => varDecl.ToAst()).ToArray(), methodBodyContext.statement().Select(stm => stm.ToAst()).ToArray(), methodBodyContext.expression().ToAst()));
 }