private System.Linq.Expressions.Expression[] GetDeferredSectionTemplates(DeferredSectionExpression dsex) { var fb = new FunctionBuilder(CompilationContext.Engine); var body = fb.Compile(dsex.Body.Expressions, CompilationContext.BindingContext); var inversion = fb.Compile(dsex.Inversion.Expressions, CompilationContext.BindingContext); var sectionPrefix = dsex.Path.Path.Substring(0, 1); switch (sectionPrefix) { case "#": return(new[] { body, inversion }); case "^": return(new[] { inversion, body }); default: throw new HandlebarsCompilerException("Tried to compile a section expression that did not begin with # or ^"); } }
protected virtual Expression VisitDeferredSectionExpression(DeferredSectionExpression dsex) { return(dsex); }
protected override System.Linq.Expressions.Expression VisitDeferredSectionExpression(DeferredSectionExpression dsex) { #if netstandard var method = new Action <object, BindingContext, Action <TextWriter, object>, Action <TextWriter, object> >(RenderSection).GetMethodInfo(); #else var method = new Action <object, BindingContext, Action <TextWriter, object>, Action <TextWriter, object> >(RenderSection).Method; #endif System.Linq.Expressions.Expression path = HandlebarsExpression.PathExpression(dsex.Path.Path.Substring(1)); System.Linq.Expressions.Expression context = CompilationContext.BindingContext; System.Linq.Expressions.Expression[] templates = GetDeferredSectionTemplates(dsex); return(System.Linq.Expressions.Expression.Call(method, new[] { path, context }.Concat(templates))); }
protected virtual System.Linq.Expressions.Expression VisitDeferredSectionExpression(DeferredSectionExpression dsex) { return(dsex); }