Skip to content

Commit d179261

Browse files
authored
Json indentation level fix (#1618)
fixes #1607
1 parent e72ddfb commit d179261

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/BenchmarkDotNet/Exporters/Json/SimpleJson.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ public static T DeserializeObject<T>(string json)
606606
public static string SerializeObject(object json, IJsonSerializerStrategy jsonSerializerStrategy)
607607
{
608608
StringBuilder builder = new StringBuilder(BUILDER_CAPACITY);
609-
ResetIndentationLevel();
610609
bool success = SerializeValue(jsonSerializerStrategy, json, builder);
610+
ResetIndentationText();
611611
return (success ? builder.ToString() : null);
612612
}
613613

@@ -1239,20 +1239,20 @@ internal static object ReplaceUnsupportedNumericValues(object value)
12391239
}
12401240
}
12411241

1242-
private static int indentationLevel;
1242+
private const char WhiteSpaceCharacter = ' ';
1243+
private static int indentationLevel = 0;
12431244
private static string indentationText;
12441245
private static readonly int spacesPerIndent = 3;
12451246

1246-
private static void ResetIndentationLevel()
1247+
private static void ResetIndentationText()
12471248
{
1248-
indentationLevel = 0;
1249-
indentationText = Environment.NewLine + new string(' ', indentationLevel * spacesPerIndent);
1249+
indentationText = Environment.NewLine;
12501250
}
12511251

12521252
private static void HandleIndent(int change)
12531253
{
12541254
indentationLevel += change;
1255-
indentationText = Environment.NewLine + new string(' ', indentationLevel * spacesPerIndent);
1255+
indentationText = Environment.NewLine + new string(WhiteSpaceCharacter, indentationLevel * spacesPerIndent);
12561256
}
12571257

12581258
private static IJsonSerializerStrategy _currentJsonSerializerStrategy;

0 commit comments

Comments
 (0)