Skip to content

Commit

Permalink
Fix review comments for #207 (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pliner authored Jan 6, 2023
1 parent f9a6f42 commit eb0489d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Source/EasyNetQ.Management.Client/Serialization/ObjectHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace EasyNetQ.Management.Client.Serialization;

internal static class ObjectHelpers
{
private static readonly object False = false;
private static readonly object True = true;

public static void WriteObjectValue(this Utf8JsonWriter writer, object? value)
{
switch (value)
Expand Down Expand Up @@ -43,7 +46,7 @@ public static void WriteObjectValue(this Utf8JsonWriter writer, object? value)
writer.WriteEndArray();
return;
default:
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(value), value, null);
}
}

Expand All @@ -66,9 +69,9 @@ public static void WriteObjectValue(this Utf8JsonWriter writer, object? value)
return new ReadOnlyDictionary<string, object?>(dictionary);
}
case { ValueKind: JsonValueKind.True }:
return true;
return True;
case { ValueKind: JsonValueKind.False }:
return false;
return False;
case { ValueKind: JsonValueKind.Number }:
return jsonElement.TryGetInt64(out var longValue) ? longValue : jsonElement.GetDouble();
case { ValueKind: JsonValueKind.String }:
Expand All @@ -79,7 +82,7 @@ public static void WriteObjectValue(this Utf8JsonWriter writer, object? value)
case { ValueKind: JsonValueKind.Null }:
return null;
default:
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(jsonElement), jsonElement, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ internal sealed class StringObjectReadOnlyDictionaryConverter : JsonConverter<IR

switch (jsonElement)
{
case { ValueKind: JsonValueKind.Array } when jsonElement.GetArrayLength() > 0:
throw new JsonException("Empty array is required");
case { ValueKind: JsonValueKind.Array }:
return new ReadOnlyDictionary<string, object?>(new Dictionary<string, object?>());
case { ValueKind: JsonValueKind.Object }:
Expand Down

0 comments on commit eb0489d

Please sign in to comment.