Exemplo n.º 1
0
 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))
         );
 }
Exemplo n.º 2
0
        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))
                       ));
        }
Exemplo n.º 3
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) 
             }));
 }
Exemplo n.º 4
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)
            })));
        }
 protected virtual Expression VisitIteratorExpression(IteratorExpression iex)
 {
     return iex;
 }
Exemplo n.º 6
0
 protected virtual Expression VisitIteratorExpression(IteratorExpression iex)
 {
     return(iex);
 }