コード例 #1
0
ファイル: pretty_print.cs プロジェクト: kylepantall/kscript
        public void Iterate(IArray item, int index, IndentedTextWriter writer, int indentation = 0, bool LastItem = false)
        {
            writer.Indent = indentation;
            if (item.HasChildren())
            {
                writer.WriteLine($"[{GetKey(item.Key, index)}] => {{");
                indentation++;

                var collection = item.GetCollection().GetItems();
                var lastItem   = collection.Last();

                foreach (var child in collection)
                {
                    bool lastChild = lastItem.Equals(child);
                    Iterate(child,
                            collection.IndexOf(child),
                            writer,
                            indentation,
                            lastChild);
                }

                indentation--;
                writer.Indent = indentation;
                writer.WriteLine($"}}{(LastItem ? "" : ",")}");
                return;
            }

            writer.WriteLine($"[{GetKey(item.Key, index)}] => \"{item.GetValue()}\"{(LastItem ? "" : ",")}");
        }