protected override Expression VisitBlockHelperExpression(BlockHelperExpression bhex)
 {
     return(HandlebarsExpression.BlockHelperExpression(
                bhex.HelperName,
                bhex.Arguments.Select(Visit),
                Visit(bhex.Body),
                Visit(bhex.Inversion)));
 }
Example #2
0
        protected override Expression VisitBlockHelperExpression(BlockHelperExpression bhex)
        {
            var fb        = new FunctionBuilder(CompilationContext.Configuration);
            var body      = fb.Compile(((BlockExpression)bhex.Body).Expressions, CompilationContext.BindingContext);
            var inversion = fb.Compile(((BlockExpression)bhex.Inversion).Expressions, CompilationContext.BindingContext);
            var helper    = CompilationContext.Configuration.BlockHelpers[bhex.HelperName.Replace("#", "")];
            var arguments = new Expression[]
            {
                Expression.Property(
                    CompilationContext.BindingContext,
                    typeof(BindingContext).GetProperty("TextWriter")),
                Expression.New(
                    typeof(HelperOptions).GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0],
                    body,
                    inversion),
                Expression.Property(
                    CompilationContext.BindingContext,
                    typeof(BindingContext).GetProperty("Value")),
                Expression.NewArrayInit(typeof(object), bhex.Arguments)
            };

            if (helper.Target != null)
            {
                return(Expression.Call(
                           Expression.Constant(helper.Target),
#if netstandard
                           helper.GetMethodInfo(),
#else
                           helper.Method,
#endif
                           arguments));
            }
            else
            {
                return(Expression.Call(
#if netstandard
                           helper.GetMethodInfo(),
#else
                           helper.Method,
#endif
                           arguments));
            }
        }
Example #3
0
 protected virtual Expression VisitBlockHelperExpression(BlockHelperExpression bhex)
 {
     return(bhex);
 }
Example #4
0
 protected virtual System.Linq.Expressions.Expression VisitBlockHelperExpression(BlockHelperExpression bhex)
 {
     return(bhex);
 }
        protected override System.Linq.Expressions.Expression VisitBlockHelperExpression(BlockHelperExpression bhex)
        {
            var isInlinePartial = bhex.HelperName == "#*inline";

            var fb = new FunctionBuilder(CompilationContext.Configuration);


            var bindingContext = isInlinePartial ? (System.Linq.Expressions.Expression)CompilationContext.BindingContext :
                                 System.Linq.Expressions.Expression.Property(
                CompilationContext.BindingContext,
                typeof(BindingContext).GetProperty("Value"));

            var body      = fb.Compile(((BlockExpression)bhex.Body).Expressions, CompilationContext.BindingContext);
            var inversion = fb.Compile(((BlockExpression)bhex.Inversion).Expressions, CompilationContext.BindingContext);
            var helper    = CompilationContext.Configuration.BlockHelpers[bhex.HelperName.Replace("#", "")];
            var arguments = new System.Linq.Expressions.Expression[]
            {
                System.Linq.Expressions.Expression.Property(
                    CompilationContext.BindingContext,
                    typeof(BindingContext).GetProperty("TextWriter")),
                System.Linq.Expressions.Expression.New(
                    typeof(HelperOptions).GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0],
                    body,
                    inversion),
                //this next arg is usually data, like { first: "Marc" }
                //but for inline partials this is the complete BindingContext.
                bindingContext,
                System.Linq.Expressions.Expression.NewArrayInit(typeof(object), bhex.Arguments)
            };


            if (helper.Target != null)
            {
                return(System.Linq.Expressions.Expression.Call(
                           System.Linq.Expressions.Expression.Constant(helper.Target),
#if netstandard
                           helper.GetMethodInfo(),
#else
                           helper.Method,
#endif
                           arguments));
            }
            else
            {
                return(System.Linq.Expressions.Expression.Call(
#if netstandard
                           helper.GetMethodInfo(),
#else
                           helper.Method,
#endif
                           arguments));
            }
        }