Create() public static method

public static Create ( Expression item, HandlebarsConfiguration configuration ) : BlockAccumulatorContext
item System.Linq.Expressions.Expression
configuration HandlebarsConfiguration
return BlockAccumulatorContext
Exemplo n.º 1
0
        public override IEnumerable <object> ConvertTokens(IEnumerable <object> sequence)
        {
            var enumerator = sequence.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var item    = (Expression)enumerator.Current;
                var context = BlockAccumulatorContext.Create(item, _configuration);
                if (context != null)
                {
                    yield return(AccumulateBlock(enumerator, context));
                }
                else
                {
                    yield return(item);
                }
            }
        }
Exemplo n.º 2
0
 private Expression AccumulateBlock(
     IEnumerator <object> enumerator,
     BlockAccumulatorContext context)
 {
     while (enumerator.MoveNext())
     {
         var item         = (Expression)enumerator.Current;
         var innerContext = BlockAccumulatorContext.Create(item, _configuration);
         if (innerContext != null)
         {
             context.HandleElement(AccumulateBlock(enumerator, innerContext));
         }
         else if (context.IsClosingElement(item))
         {
             return(context.GetAccumulatedBlock());
         }
         else
         {
             context.HandleElement(item);
         }
     }
     throw new HandlebarsCompilerException($"Reached end of template before block expression '{context.BlockName}' was closed");
 }