Example #1
0
        private void createTheReturnValue(ParameterExpression variable, BlockPlan plan)
        {
            var        label        = Expression.Label(_pluginType);
            Expression returnTarget = variable;

            plan.Add(Expression.Return(label, returnTarget, _pluginType));
            plan.Add(Expression.Label(label, variable));
        }
        private void addDecorators(ParameterExpression context, ParameterExpression pluginTypeVariable, BlockPlan plan)
        {
            _decorators.Each(decorator => {
                var decoratedExpression = decorator.ToExpression(_policies, context, pluginTypeVariable);
                var wrapped             =
                    TryCatchWrapper.WrapFunc <StructureMapInterceptorException>(
                        "Decorator Interceptor failed during object construction.  See the inner exception", _pluginType,
                        decoratedExpression, decorator);

                plan.Add(Expression.Assign(pluginTypeVariable, wrapped));
            });
        }
        private ParameterExpression addPluginTypeVariable(BlockPlan plan)
        {
            var pluginTypeVariable = plan.FindVariableOfType(_pluginType);

            if (pluginTypeVariable == null)
            {
                pluginTypeVariable = Expression.Variable(_pluginType, "returnValue");
                plan.AddVariable(pluginTypeVariable);

                plan.Add(Expression.Assign(pluginTypeVariable, Expression.Convert(_variable, _pluginType)));
            }
            return(pluginTypeVariable);
        }
        public Expression ToExpression(ParameterExpression session, ParameterExpression context)
        {
            // Seed the plan with the inner value
            var inner = _inner.ToExpression(session, context);
            var plan  = new BlockPlan();

            plan.AddVariable(_variable);
            var assignment = Expression.Assign(_variable, inner);

            plan.Add(assignment);

            addActivations(plan);

            var pluginTypeVariable = addPluginTypeVariable(plan);

            addDecorators(context, pluginTypeVariable, plan);

            createTheReturnValue(pluginTypeVariable, plan);

            return(plan.ToExpression());
        }
 private void addActivations(BlockPlan plan)
 {
     plan.AddVariables(_activators.SelectMany(x => x.ToParameterExpressions(_inner.ReturnedType)));
     plan.Add(_activators.SelectMany(x => x.CreateExpressions(_policies, _variable)).ToArray());
 }