Esempio n. 1
0
        public void Visit(Block block)
        {
            parts.Add(context.GetInnerExpressions(block.Name, value =>
            {
                context.Push(block, value);

                if (typeof(Lambda <string>).BaseType.IsAssignableFrom(value.Type))
                {
                    return
                    (Expression.Call(
                         Expression.Call(value, value.Type.GetMethod("Invoke"),
                                         Expression.Constant(block.InnerSource())),
                         typeof(object).GetMethod("ToString")));
                }

                var visitor = new CompilePartVisitor(context);
                visitor.Visit((Section)block);
                var expression = CompoundExpression.NullCheck(value,
                                                              nullValue: "",
                                                              returnIfNotNull: visitor.Result());

                context.Pop();

                return(expression);
            }));
        }
Esempio n. 2
0
        public void Visit(Block block)
        {
            parts.Add(context.GetInnerExpressions(block.Name, value =>
            {
                context.Push(block, value);

                if (typeof(Lambda<string>).BaseType.IsAssignableFrom(value.Type))
                {
                    return
                        Expression.Call(
                            Expression.Call(value, value.Type.GetMethod("Invoke"),
                                Expression.Constant(block.InnerSource())),
                            typeof(object).GetMethod("ToString"));
                }

                var visitor = new CompilePartVisitor(context);
                visitor.Visit((Section)block);
                var expression = CompoundExpression.NullCheck(value,
                    nullValue: "",
                    returnIfNotNull: visitor.Result());

                context.Pop();

                return expression;
            }));
        }
Esempio n. 3
0
        public static Expression Compile(this Template template, CompileContext context)
        {
            var visitor = new CompilePartVisitor(context);

            visitor.Visit(template);
            return(visitor.Result());
        }
Esempio n. 4
0
        public void Visit(InvertedBlock invertedBlock)
        {
            parts.Add(context.GetInnerExpressions(invertedBlock.Name, value =>
            {
                // the logic here is really confusing, but since GetInnerExpressions does
                // the truthiness check, it is basically the same as Block.Compile

                var visitor = new CompilePartVisitor(context);
                visitor.Visit((Section)invertedBlock);
                var expression = visitor.Result();

                return(expression);
            }, invert: true));
        }
Esempio n. 5
0
        public void Visit(InvertedBlock invertedBlock)
        {
            parts.Add(context.GetInnerExpressions(invertedBlock.Name, value =>
            {
                // the logic here is really confusing, but since GetInnerExpressions does 
                // the truthiness check, it is basically the same as Block.Compile

                var visitor = new CompilePartVisitor(context);
                visitor.Visit((Section)invertedBlock);
                var expression = visitor.Result();

                return expression;
            }, invert: true));
        }