mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
Added specific type fields for NodeAccessor to prevent boxing
This commit is contained in:
parent
926802d953
commit
db9fba4cf2
@ -20,7 +20,7 @@ namespace CryptoExchange.Net.Converters.JsonNet
|
|||||||
/// The json token loaded
|
/// The json token loaded
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected JToken? _token;
|
protected JToken? _token;
|
||||||
private static JsonSerializer _serializer = JsonSerializer.Create(SerializerOptions.WithConverters);
|
private static readonly JsonSerializer _serializer = JsonSerializer.Create(SerializerOptions.WithConverters);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsJson { get; protected set; }
|
public bool IsJson { get; protected set; }
|
||||||
@ -174,7 +174,7 @@ namespace CryptoExchange.Net.Converters.JsonNet
|
|||||||
if (node.Type == 0)
|
if (node.Type == 0)
|
||||||
{
|
{
|
||||||
// Int value
|
// Int value
|
||||||
var val = (int)node.Value!;
|
var val = node.Index!.Value;
|
||||||
if (currentToken!.Type != JTokenType.Array || ((JArray)currentToken).Count <= val)
|
if (currentToken!.Type != JTokenType.Array || ((JArray)currentToken).Count <= val)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ namespace CryptoExchange.Net.Converters.JsonNet
|
|||||||
if (currentToken!.Type != JTokenType.Object)
|
if (currentToken!.Type != JTokenType.Object)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
currentToken = currentToken[(string)node.Value!];
|
currentToken = currentToken[node.Property!];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -6,17 +6,23 @@
|
|||||||
public struct NodeAccessor
|
public struct NodeAccessor
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Value
|
/// Index
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object? Value { get; }
|
public int? Index { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Property name
|
||||||
|
/// </summary>
|
||||||
|
public string? Property { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Type (0 = int, 1 = string, 2 = prop name)
|
/// Type (0 = int, 1 = string, 2 = prop name)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Type { get; }
|
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;
|
Type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,20 +31,19 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
/// <returns></returns>
|
/// <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>
|
/// <summary>
|
||||||
/// Create a string node accessor
|
/// Create a string node accessor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
/// <returns></returns>
|
/// <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>
|
/// <summary>
|
||||||
/// Create a property name node accessor
|
/// Create a property name node accessor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static NodeAccessor PropertyName() { return new NodeAccessor(null, 2); }
|
public static NodeAccessor PropertyName() { return new NodeAccessor(null, null, 2); }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
|||||||
if (node.Type == 0)
|
if (node.Type == 0)
|
||||||
{
|
{
|
||||||
// Int value
|
// Int value
|
||||||
var val = (int)node.Value!;
|
var val = node.Index!.Value;
|
||||||
if (currentToken!.Value.ValueKind != JsonValueKind.Array || currentToken.Value.GetArrayLength() <= val)
|
if (currentToken!.Value.ValueKind != JsonValueKind.Array || currentToken.Value.GetArrayLength() <= val)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
|||||||
if (currentToken!.Value.ValueKind != JsonValueKind.Object)
|
if (currentToken!.Value.ValueKind != JsonValueKind.Object)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (!currentToken.Value.TryGetProperty((string)node.Value!, out var token))
|
if (!currentToken.Value.TryGetProperty(node.Property!, out var token))
|
||||||
return null;
|
return null;
|
||||||
currentToken = token;
|
currentToken = token;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user