internal string ToStringFormatted(ref int indentLevel) { // Purpose: Convert this JObject into a string with formatting // Author : Scott Bakker // Created: 10/17/2019 // LastMod: 08/11/2020 if (_data.Count == 0) { return("{}"); // avoid indent errors } StringBuilder result = new StringBuilder(); result.Append('{'); if (indentLevel >= 0) { result.AppendLine(); indentLevel++; } bool addComma = false; foreach (KeyValuePair <string, object> kv in _data) { if (addComma) { result.Append(','); if (indentLevel >= 0) { result.AppendLine(); } } else { addComma = true; } if (indentLevel > 0) { result.Append(JsonRoutines.IndentSpace(indentLevel)); } result.Append(JsonRoutines.ValueToString(kv.Key)); result.Append(':'); if (indentLevel >= 0) { result.Append(' '); } result.Append(JsonRoutines.ValueToString(kv.Value, ref indentLevel)); } if (indentLevel >= 0) { result.AppendLine(); if (indentLevel > 0) { indentLevel--; } result.Append(JsonRoutines.IndentSpace(indentLevel)); } result.Append('}'); return(result.ToString()); }
internal string ToStringFormatted(ref int indentLevel) { // Purpose: Convert this JArray into a string with formatting // Author : Scott Bakker // Created: 10/17/2019 // LastMod: 03/09/2021 if (_data.Count == 0) { return("[]"); // avoid indent errors } StringBuilder result = new(); result.Append('['); if (indentLevel >= 0) { result.AppendLine(); indentLevel++; } bool addComma = false; foreach (object obj in _data) { if (addComma) { result.Append(','); if (indentLevel >= 0) { result.AppendLine(); } } else { addComma = true; } if (indentLevel > 0) { result.Append(JsonRoutines.IndentSpace(indentLevel)); } result.Append(JsonRoutines.ValueToString(obj, ref indentLevel)); } if (indentLevel >= 0) { result.AppendLine(); if (indentLevel > 0) { indentLevel--; } result.Append(JsonRoutines.IndentSpace(indentLevel)); } result.Append(']'); return(result.ToString()); }