Ejemplo n.º 1
0
        public override void Stringify(StreamWriter writer, StringifyOptions options)
        {
            writer.Write('"');

            for (int i = 0; i < Value.Length; i++)
            {
                switch (Value[i])
                {
                case '"': writer.Write("\\\""); break;

                case '\\': writer.Write("\\\\"); break;

                case '/': writer.Write("\\/"); break;

                case '\n': writer.Write("\\n"); break;

                case '\r': writer.Write("\\r"); break;

                case '\t': writer.Write("\\t"); break;

                default: writer.Write(Value[i]); break;
                }
            }

            writer.Write('"');
        }
Ejemplo n.º 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 (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('}');
        }
Ejemplo n.º 3
0
 public override void Stringify(StreamWriter writer, StringifyOptions options)
 {
     if (Value)
     {
         writer.Write("true");
     }
     else
     {
         writer.Write("false");
     }
 }
Ejemplo n.º 4
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(']');
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Serializes the entity into a string
        /// </summary>
        public string Stringify(StringifyOptions options = new StringifyOptions())
        {
            using (MemoryStream stream = new MemoryStream())
                using (StreamWriter writer = new StreamWriter(stream))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        this.Stringify(writer, options);

                        writer.Flush();

                        stream.Position = 0;

                        return(reader.ReadToEnd());
                    }
        }
Ejemplo n.º 6
0
 public override void Stringify(StreamWriter writer, StringifyOptions options)
 {
     writer.Write("null");
 }
Ejemplo n.º 7
0
 public override void Stringify(StreamWriter writer, StringifyOptions options)
 {
     writer.Write(this.Value.ToString());
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Serializes the entity into a string written to a string writer
 /// </summary>
 public abstract void Stringify(StreamWriter writer, StringifyOptions options);