Exemple #1
0
 private void BuildPrettyString(IndentedWriter writer)
 {
     if (IsPrimitive)
     {
         Primitive_BuildPrettyString(writer);
     }
     else if (IsObject)
     {
         Object_BuildPrettyString(writer);
     }
     else if (IsArray)
     {
         Array_BuildPrettyString(writer);
     }
     else
     {
         throw AssertionHelper.Fail();
     }
 }
Exemple #2
0
        private void Object_BuildPrettyString(IndentedWriter writer)
        {
            writer.Write("{");
            writer.Indent++;

            var keys = Keys.AssertCast<String>();
            if (keys.IsNotEmpty())
            {
                keys.ForEach((key, i) =>
                {
                    writer.WriteLine();
                    writer.Write("\"{0}\" : ", key);
                    if (((IEnumerable)this[key].Keys).Cast<Object>().Count() > 0) writer.WriteLine();
                    this[key].BuildPrettyString(writer);
                    if (i < this.Count() - 1) writer.Write(",");
                });

                writer.WriteLine();
            }

            writer.Indent--;
            writer.Write("}");
        }
Exemple #3
0
        private void Array_BuildPrettyString(IndentedWriter writer)
        {
            writer.Write("[");
            writer.Indent++;

            var keys = Keys.AssertCast<int>();
            if (keys.IsNotEmpty())
            {
                keys.ForEach((key, i) =>
                {
                    (key == i).AssertTrue();
                    // todo. omg what's with these dynamic invocations?!
                    if (((IEnumerable)this[key].Keys).Cast<Object>().Count() > 0) writer.WriteLine();
                    this[key].BuildPrettyString(writer);
                    if (i < this.Count() - 1) writer.Write(",");
                });

                writer.WriteLine();
            }

            writer.Indent--;
            writer.Write("]");
        }
Exemple #4
0
 private void Primitive_BuildPrettyString(IndentedWriter writer)
 {
     Primitive_BuildCompactString(writer);
 }