mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 00:16:27 +00:00
Added checks
This commit is contained in:
parent
27704bf090
commit
61aa589cda
@ -63,6 +63,9 @@ namespace CryptoExchange.Net.Sockets.MessageParsing
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public NodeType? GetNodeType()
|
public NodeType? GetNodeType()
|
||||||
{
|
{
|
||||||
|
if (!IsJson)
|
||||||
|
throw new InvalidOperationException("Can't access json data on non-json message");
|
||||||
|
|
||||||
if (_token == null)
|
if (_token == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -78,6 +81,9 @@ namespace CryptoExchange.Net.Sockets.MessageParsing
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public NodeType? GetNodeType(MessagePath path)
|
public NodeType? GetNodeType(MessagePath path)
|
||||||
{
|
{
|
||||||
|
if (!IsJson)
|
||||||
|
throw new InvalidOperationException("Can't access json data on non-json message");
|
||||||
|
|
||||||
var node = GetPathNode(path);
|
var node = GetPathNode(path);
|
||||||
if (node == null)
|
if (node == null)
|
||||||
return null;
|
return null;
|
||||||
@ -94,6 +100,9 @@ namespace CryptoExchange.Net.Sockets.MessageParsing
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public T? GetValue<T>(MessagePath path)
|
public T? GetValue<T>(MessagePath path)
|
||||||
{
|
{
|
||||||
|
if (!IsJson)
|
||||||
|
throw new InvalidOperationException("Can't access json data on non-json message");
|
||||||
|
|
||||||
var value = GetPathNode(path);
|
var value = GetPathNode(path);
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return default;
|
return default;
|
||||||
@ -107,6 +116,9 @@ namespace CryptoExchange.Net.Sockets.MessageParsing
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public List<T?>? GetValues<T>(MessagePath path)
|
public List<T?>? GetValues<T>(MessagePath path)
|
||||||
{
|
{
|
||||||
|
if (!IsJson)
|
||||||
|
throw new InvalidOperationException("Can't access json data on non-json message");
|
||||||
|
|
||||||
var value = GetPathNode(path);
|
var value = GetPathNode(path);
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return default;
|
return default;
|
||||||
@ -119,6 +131,9 @@ namespace CryptoExchange.Net.Sockets.MessageParsing
|
|||||||
|
|
||||||
private JToken? GetPathNode(MessagePath path)
|
private JToken? GetPathNode(MessagePath path)
|
||||||
{
|
{
|
||||||
|
if (!IsJson)
|
||||||
|
throw new InvalidOperationException("Can't access json data on non-json message");
|
||||||
|
|
||||||
var currentToken = _token;
|
var currentToken = _token;
|
||||||
foreach (var node in path)
|
foreach (var node in path)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user