Example #1
0
        private async Promise CoreAction(IByteCounterStream outputStream,
                                         ContextObject c,
                                         ScopeData scopeData,
                                         Func <ContextObject, Promise> onItem)
        {
            if (!c.Exists())
            {
                return;
            }

            if (!(c.Value is IEnumerable value) || value is string || value is IDictionary <string, object> )
            {
                var path   = new Stack <string>();
                var parent = c.Parent;
                while (parent != null)
                {
                    path.Push(parent.Key);
                    parent = parent.Parent;
                }

                throw new IndexedParseException(CharacterLocationExtended.Empty,
                                                string.Format(
                                                    "{1}'{0}' is used like an array by the template, but is a scalar value or object in your model." +
                                                    " Complete Expression until Error:{2}",
                                                    MorestachioExpression, ExpressionStart,
                                                    (path.Count == 0 ? "Empty" : path.Aggregate((e, f) => e + "\r\n" + f))));
            }

            if (value is ICollection col)
            {
                await LoopCollection(outputStream, c, scopeData, onItem, col);
            }
            else
            {
                await LoopEnumerable(outputStream, c, scopeData, onItem, value);
            }
        }