protected override Expression VisitBlockHelperExpression(BlockHelperExpression bhex)
 {
     var fb = new FunctionBuilder(_context.Configuration);
     var body = fb.Compile(((BlockExpression)bhex.Body).Expressions, _context.BindingContext);
     var helper = _context.Configuration.BlockHelpers[bhex.HelperName.Replace("#", "")];
     var arguments = new Expression[] {
         Expression.Property(
             _context.BindingContext,
             typeof(BindingContext).GetProperty("TextWriter")),
         body,
         Expression.Property(
             _context.BindingContext,
             typeof(BindingContext).GetProperty("Value")),
         Expression.NewArrayInit(typeof(object), bhex.Arguments)
     };
     if(helper.Target != null)
     {
         return Expression.Call(
             Expression.Constant(helper.Target),
             helper.Method,
             arguments);
     }
     else
     {
         return Expression.Call(
             helper.Method,
             arguments);
     }
 }
Пример #2
0
 private Expression GetObjectIterator(Expression contextParameter, IteratorExpression iex)
 {
     var fb = new FunctionBuilder(_context.Configuration);
     return Expression.Block(
         Expression.Assign(contextParameter,
             Expression.New(
                 typeof(ObjectEnumeratorBindingContext).GetConstructor(new[] { typeof(BindingContext) }),
                 new Expression[] { _context.BindingContext })),
         Expression.Call(
             new Action<ObjectEnumeratorBindingContext, object, Action<TextWriter, object>, Action<TextWriter, object>>(Iterate).Method,
             new Expression[] {
                 Expression.Convert(contextParameter, typeof(ObjectEnumeratorBindingContext)),
                 iex.Sequence,
                 fb.Compile(new [] { iex.Template }, contextParameter),
                 fb.Compile(new [] { iex.IfEmpty }, _context.BindingContext) 
             }));
 }
Пример #3
0
 public HandlebarsCompiler(HandlebarsConfiguration configuration)
 {
     _tokenizer         = new Tokenizer(configuration);
     _expressionBuilder = new ExpressionBuilder(configuration);
     _functionBuilder   = new FunctionBuilder(configuration);
 }
 public HandlebarsCompiler(HandlebarsConfiguration configuration)
 {
     _tokenizer = new Tokenizer(configuration);
     _expressionBuilder = new ExpressionBuilder(configuration);
     _functionBuilder = new FunctionBuilder(configuration);
 }