예제 #1
0
        public override void Stringify(StreamWriter writer, StringifyOptions options)
        {
            if (Items.Count == 0)
            {
                if (options.Inlined)
                {
                    writer.Write("{}");
                }
                else
                {
                    writer.Write("{");
                    options.BreakLine(writer);
                    writer.Write("}");
                }

                return;
            }

            writer.Write('{');

            options.currentIndent++;
            options.BreakLine(writer);

            int index = 0;

            foreach (KeyValuePair <string, JsonEntity> i in Items)
            {
                new JsonString(i.Key).Stringify(writer, options);
                writer.Write(": ");
                i.Value.Stringify(writer, options);

                // if not the last line
                if (index < Items.Count - 1)
                {
                    writer.Write(",");

                    if (options.Inlined)
                    {
                        writer.Write(" ");
                    }
                    else
                    {
                        options.BreakLine(writer);
                    }
                }

                index++;
            }

            // on last line
            options.currentIndent--;
            options.BreakLine(writer);

            writer.Write('}');
        }
예제 #2
0
        public override void Stringify(StreamWriter writer, StringifyOptions options)
        {
            if (Items.Count == 0)
            {
                if (options.Inlined)
                {
                    writer.Write("[]");
                }
                else
                {
                    writer.Write("[");
                    options.BreakLine(writer);
                    writer.Write("]");
                }

                return;
            }

            writer.Write('[');

            options.currentIndent++;
            options.BreakLine(writer);

            int index = 0;

            foreach (JsonEntity i in Items)
            {
                i.Stringify(writer, options);

                // if not the last line
                if (index < Items.Count - 1)
                {
                    writer.Write(",");

                    if (options.Inlined)
                    {
                        writer.Write(" ");
                    }
                    else
                    {
                        options.BreakLine(writer);
                    }
                }

                index++;
            }

            options.currentIndent--;
            options.BreakLine(writer);

            writer.Write(']');
        }