diff --git a/CryptoExchange.Net/Converters/JsonNet/JsonNetMessageAccessor.cs b/CryptoExchange.Net/Converters/JsonNet/JsonNetMessageAccessor.cs index 0c6d749..9aa1e80 100644 --- a/CryptoExchange.Net/Converters/JsonNet/JsonNetMessageAccessor.cs +++ b/CryptoExchange.Net/Converters/JsonNet/JsonNetMessageAccessor.cs @@ -20,7 +20,7 @@ namespace CryptoExchange.Net.Converters.JsonNet /// The json token loaded /// </summary> protected JToken? _token; - private static JsonSerializer _serializer = JsonSerializer.Create(SerializerOptions.WithConverters); + private static readonly JsonSerializer _serializer = JsonSerializer.Create(SerializerOptions.WithConverters); /// <inheritdoc /> public bool IsJson { get; protected set; } @@ -174,7 +174,7 @@ namespace CryptoExchange.Net.Converters.JsonNet if (node.Type == 0) { // Int value - var val = (int)node.Value!; + var val = node.Index!.Value; if (currentToken!.Type != JTokenType.Array || ((JArray)currentToken).Count <= val) return null; @@ -186,7 +186,7 @@ namespace CryptoExchange.Net.Converters.JsonNet if (currentToken!.Type != JTokenType.Object) return null; - currentToken = currentToken[(string)node.Value!]; + currentToken = currentToken[node.Property!]; } else { diff --git a/CryptoExchange.Net/Converters/MessageParsing/MessageNode.cs b/CryptoExchange.Net/Converters/MessageParsing/MessageNode.cs index 01b23bf..2a9782e 100644 --- a/CryptoExchange.Net/Converters/MessageParsing/MessageNode.cs +++ b/CryptoExchange.Net/Converters/MessageParsing/MessageNode.cs @@ -6,17 +6,23 @@ public struct NodeAccessor { /// <summary> - /// Value + /// Index /// </summary> - public object? Value { get; } + public int? Index { get; } + /// <summary> + /// Property name + /// </summary> + public string? Property { get; } + /// <summary> /// Type (0 = int, 1 = string, 2 = prop name) /// </summary> public int Type { get; } - private NodeAccessor(object? value, int type) + private NodeAccessor(int? index, string? property, int type) { - Value = value; + Index = index; + Property = property; Type = type; } @@ -25,20 +31,19 @@ /// </summary> /// <param name="value"></param> /// <returns></returns> - public static NodeAccessor Int(int value) { return new NodeAccessor(value, 0); } + public static NodeAccessor Int(int value) { return new NodeAccessor(value, null, 0); } /// <summary> /// Create a string node accessor /// </summary> /// <param name="value"></param> /// <returns></returns> - public static NodeAccessor String(string value) { return new NodeAccessor(value, 1); } + public static NodeAccessor String(string value) { return new NodeAccessor(null, value, 1); } /// <summary> /// Create a property name node accessor /// </summary> /// <returns></returns> - public static NodeAccessor PropertyName() { return new NodeAccessor(null, 2); } + public static NodeAccessor PropertyName() { return new NodeAccessor(null, null, 2); } } - } diff --git a/CryptoExchange.Net/Converters/SystemTextJson/SystemTextJsonMessageAccessor.cs b/CryptoExchange.Net/Converters/SystemTextJson/SystemTextJsonMessageAccessor.cs index 020003d..c65be56 100644 --- a/CryptoExchange.Net/Converters/SystemTextJson/SystemTextJsonMessageAccessor.cs +++ b/CryptoExchange.Net/Converters/SystemTextJson/SystemTextJsonMessageAccessor.cs @@ -147,7 +147,7 @@ namespace CryptoExchange.Net.Converters.SystemTextJson if (node.Type == 0) { // Int value - var val = (int)node.Value!; + var val = node.Index!.Value; if (currentToken!.Value.ValueKind != JsonValueKind.Array || currentToken.Value.GetArrayLength() <= val) return null; @@ -159,7 +159,7 @@ namespace CryptoExchange.Net.Converters.SystemTextJson if (currentToken!.Value.ValueKind != JsonValueKind.Object) return null; - if (!currentToken.Value.TryGetProperty((string)node.Value!, out var token)) + if (!currentToken.Value.TryGetProperty(node.Property!, out var token)) return null; currentToken = token; }