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); })); }
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); } }
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)); } }