Skip to content

Commit

Permalink
Remove redundant Debug.Assert; Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andreise committed Dec 25, 2024
1 parent 58eab52 commit d15f3ca
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/core-unit/Unit/UnitJsonConverter/UnitJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace System;
Expand All @@ -8,17 +7,11 @@ internal sealed class UnitJsonConverter : JsonConverter<Unit>
{
public override Unit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var tokenType = reader.TokenType;
Debug.Assert(tokenType is not JsonTokenType.None);

switch (tokenType)
switch (reader.TokenType)
{
case JsonTokenType.StartObject:
case JsonTokenType.StartArray:
reader.Skip();
Debug.Assert(
tokenType is JsonTokenType.StartObject && reader.TokenType is JsonTokenType.EndObject ||
tokenType is JsonTokenType.StartArray && reader.TokenType is JsonTokenType.EndArray);
return default;

case JsonTokenType.String:
Expand All @@ -28,15 +21,13 @@ tokenType is JsonTokenType.StartObject && reader.TokenType is JsonTokenType.EndO
case JsonTokenType.Null:
return default;

default:
throw new JsonException($"An unexpected JSON token type ({tokenType}).");
case var unexpected:
throw new JsonException($"An unexpected JSON token type ({unexpected}).");
};
}

public override void Write(Utf8JsonWriter writer, Unit value, JsonSerializerOptions options)
{
Debug.Assert(writer is not null);

writer.WriteStartObject();
writer.WriteEndObject();
}
Expand Down

0 comments on commit d15f3ca

Please sign in to comment.