protected override Expression VisitDeferredSectionExpression(DeferredSectionExpression dsex)
        {
            var method = new Action <object, BindingContext, Action <TextWriter, object>, Action <TextWriter, object> >(RenderSection).Method;

            Expression path    = HandlebarsExpression.Path(dsex.Path.Path.Substring(1));
            Expression context = CompilationContext.BindingContext;

            Expression[] templates = GetDeferredSectionTemplates(dsex);

            return(Expression.Call(method, new[] { path, context }.Concat(templates)));
        }
        protected virtual Expression VisitDeferredSectionExpression(DeferredSectionExpression dsex)
        {
            PathExpression path = (PathExpression)Visit(dsex.Path);

            // Don't visit Body/Inversion - they will be compiled separately

            if (path != dsex.Path)
            {
                return(HandlebarsExpression.DeferredSection(path, dsex.Body, dsex.Inversion));
            }
            return(dsex);
        }
        protected override 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
            Expression path = HandlebarsExpression.Path(dsex.Path.Path.Substring(1));
            Expression context = CompilationContext.BindingContext;
            Expression[] templates = GetDeferredSectionTemplates(dsex);

            return Expression.Call(method, new[] {path, context}.Concat(templates));

        }
        private Expression[] GetDeferredSectionTemplates(DeferredSectionExpression dsex)
        {
            var fb = new FunctionBuilder(CompilationContext.Configuration);
            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 ^");
            }
        }
        private Expression[] GetDeferredSectionTemplates(DeferredSectionExpression dsex)
        {
            var fb        = new FunctionBuilder(CompilationContext.Configuration);
            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 override Expression VisitDeferredSectionExpression(DeferredSectionExpression dsex)
 {
     Action<object, BindingContext, Action<TextWriter, object>> method;
     if (dsex.Path.Path.StartsWith("#"))
     {
         method = RenderSection;
     }
     else if (dsex.Path.Path.StartsWith("^"))
     {
         method = RenderEmptySection;
     }
     else
     {
         throw new HandlebarsCompilerException("Tried to compile a section expression that did not begin with # or ^");
     }
     return Expression.Call(
         method.Method,
         HandlebarsExpression.Path(dsex.Path.Path.Substring(1)),
         CompilationContext.BindingContext,
         new FunctionBuilder(CompilationContext.Configuration).Compile(dsex.Body, CompilationContext.BindingContext));
 }
Beispiel #7
0
        protected override Expression VisitDeferredSectionExpression(DeferredSectionExpression dsex)
        {
            Action <object, BindingContext, Action <TextWriter, object> > method;

            if (dsex.Path.Path.StartsWith("#"))
            {
                method = RenderSection;
            }
            else if (dsex.Path.Path.StartsWith("^"))
            {
                method = RenderEmptySection;
            }
            else
            {
                throw new HandlebarsCompilerException("Tried to compile a section expression that did not begin with # or ^");
            }
            return(Expression.Call(
                       method.Method,
                       HandlebarsExpression.Path(dsex.Path.Path.Substring(1)),
                       CompilationContext.BindingContext,
                       new FunctionBuilder(CompilationContext.Configuration).Compile(dsex.Body, CompilationContext.BindingContext)));
        }
 protected virtual Expression VisitDeferredSectionExpression(DeferredSectionExpression dsex)
 {
     return dsex;
 }
Beispiel #9
0
 protected virtual Expression VisitDeferredSectionExpression(DeferredSectionExpression dsex)
 {
     return(dsex);
 }