Skip to content

Commit 3b85499

Browse files
Address code review feedback
1 parent 7f90507 commit 3b85499

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

dotnet/src/InternalUtilities/src/Text/BoolJsonConverter.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSer
2727
{
2828
return false;
2929
}
30-
if (value.Equals("true", StringComparison.OrdinalIgnoreCase))
30+
if (bool.TryParse(value, out var boolValue))
3131
{
32-
return true;
33-
}
34-
else if (value.Equals("false", StringComparison.OrdinalIgnoreCase))
35-
{
36-
return false;
32+
return boolValue;
3733
}
3834

3935
throw new ArgumentException($"Value '{value}' can be parsed as a boolean value");
@@ -53,6 +49,6 @@ public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSer
5349
/// <inheritdoc/>
5450
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
5551
{
56-
writer.WriteBooleanValue((bool)value);
52+
writer.WriteBooleanValue(value);
5753
}
5854
}

dotnet/src/InternalUtilities/src/Text/OptionalBoolJsonConverter.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ internal sealed class OptionalBoolJsonConverter : JsonConverter<bool?>
2727
{
2828
return null;
2929
}
30-
if (value.Equals("true", StringComparison.OrdinalIgnoreCase))
30+
if (bool.TryParse(value, out var boolValue))
31+
{
32+
return boolValue;
33+
}
34+
if (value.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase))
3135
{
3236
return true;
3337
}
34-
else if (value.Equals("false", StringComparison.OrdinalIgnoreCase))
38+
else if (value.Equals(bool.FalseString, StringComparison.OrdinalIgnoreCase))
3539
{
3640
return false;
3741
}

0 commit comments

Comments
 (0)