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(VariableReference variable)
        {
            var getter = context.CompiledGetter(variable.Path);

            getter = CompoundExpression.NullCheck(getter, "");
            getter = Expression.Call(getter, context.TargetType.GetMethod("ToString"));

            if (variable.Escaped)
            {
                parts.Add(Expression.Call(null, typeof(Encoders).GetMethod("DefaultHtmlEncode"), getter));
            }
            else
            {
                parts.Add(getter);
            }
        }
Esempio n. 3
0
        public void Visit(VariableReference variable)
        {
            var getter = context.CompiledGetter(variable.Path);

            getter = CompoundExpression.NullCheck(getter, "");
            getter = Expression.Call(getter, context.TargetType.GetMethod("ToString"));

            if (variable.Escaped)
            {
                var escaperProperty = typeof(Encoders).GetProperty("HtmlEncode", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                var escaperMethod   = (Delegate)escaperProperty.GetValue(null, null);
                parts.Add(CompoundExpression.IndentOnLineEnd(Expression.Call(null, escaperMethod.Method, getter), context));
            }
            else
            {
                parts.Add(CompoundExpression.IndentOnLineEnd(getter, context));
            }
        }