protected override Expression VisitIteratorExpression(IteratorExpression iex)
 {
     var iteratorBindingContext = Expression.Variable(typeof(BindingContext), "context");
     return Expression.Block(
         new ParameterExpression[] {
             iteratorBindingContext
         },
         Expression.IfThenElse(
             Expression.NotEqual(Expression.TypeAs(iex.Sequence, typeof(IEnumerable)), Expression.Constant(null)),
             GetEnumerableIterator(iteratorBindingContext, iex),
             GetObjectIterator(iteratorBindingContext, iex))
         );
 }
        protected override Expression VisitIteratorExpression(IteratorExpression iex)
        {
            var iteratorBindingContext = Expression.Variable(typeof(BindingContext), "context");

            return(Expression.Block(
                       new ParameterExpression[] {
                iteratorBindingContext
            },
                       Expression.IfThenElse(
                           Expression.NotEqual(Expression.TypeAs(iex.Sequence, typeof(IEnumerable)), Expression.Constant(null)),
                           GetEnumerableIterator(iteratorBindingContext, iex),
                           GetObjectIterator(iteratorBindingContext, iex))
                       ));
        }
 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) 
             }));
 }
        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)
            })));
        }
 protected virtual Expression VisitIteratorExpression(IteratorExpression iex)
 {
     return iex;
 }
Exemple #6
0
 protected virtual Expression VisitIteratorExpression(IteratorExpression iex)
 {
     return(iex);
 }