コード例 #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);
            }));
        }
コード例 #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);
            }
        }
コード例 #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));
            }
        }