public string ToStringSorted() { // Purpose: Sort the keys before returning as a string // Author : Scott Bakker // Created: 10/17/2019 // LastMod: 08/11/2020 StringBuilder result = new StringBuilder(); result.Append('{'); bool addComma = false; SortedList sorted = new SortedList(_data); for (int i = 0; i < sorted.Count; i++) { if (addComma) { result.Append(','); } else { addComma = true; } result.Append(JsonRoutines.ValueToString(sorted.GetKey(i))); result.Append(':'); result.Append(JsonRoutines.ValueToString(sorted.GetByIndex(i))); } result.Append('}'); return(result.ToString()); }
public override string ToString() { // Purpose: Convert this JArray into a string with no formatting // Author : Scott Bakker // Created: 09/13/2019 // LastMod: 08/11/2020 // Notes : This could be implemented as ToStringFormatted(-1) but // it is separate to get better performance. StringBuilder result = new StringBuilder(); result.Append('['); bool addComma = false; foreach (object obj in _data) { if (addComma) { result.Append(','); } else { addComma = true; } result.Append(JsonRoutines.ValueToString(obj)); } result.Append(']'); return(result.ToString()); }
public override string ToString() { // Purpose: Convert a JObject into a string // Author : Scott Bakker // Created: 09/13/2019 // LastMod: 08/11/2020 StringBuilder result = new StringBuilder(); result.Append('{'); bool addComma = false; foreach (KeyValuePair <string, object> kv in _data) { if (addComma) { result.Append(','); } else { addComma = true; } result.Append(JsonRoutines.ValueToString(kv.Key)); result.Append(':'); result.Append(JsonRoutines.ValueToString(kv.Value)); } result.Append('}'); return(result.ToString()); }
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()); }