Skip to content

Commit

Permalink
Added checks
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Mar 4, 2024
1 parent 27704bf commit 61aa589
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CryptoExchange.Net/Sockets/MessageParsing/JsonNetMessageData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public object Deserialize(Type type, MessagePath? path = null)
/// <inheritdoc />
public NodeType? GetNodeType()
{
if (!IsJson)
throw new InvalidOperationException("Can't access json data on non-json message");

if (_token == null)
return null;

Expand All @@ -78,6 +81,9 @@ public object Deserialize(Type type, MessagePath? path = null)
/// <inheritdoc />
public NodeType? GetNodeType(MessagePath path)
{
if (!IsJson)
throw new InvalidOperationException("Can't access json data on non-json message");

var node = GetPathNode(path);
if (node == null)
return null;
Expand All @@ -94,6 +100,9 @@ public object Deserialize(Type type, MessagePath? path = null)
/// <inheritdoc />
public T? GetValue<T>(MessagePath path)
{
if (!IsJson)
throw new InvalidOperationException("Can't access json data on non-json message");

var value = GetPathNode(path);
if (value == null)
return default;
Expand All @@ -107,6 +116,9 @@ public object Deserialize(Type type, MessagePath? path = null)
/// <inheritdoc />
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);
if (value == null)
return default;
Expand All @@ -119,6 +131,9 @@ public object Deserialize(Type type, MessagePath? path = null)

private JToken? GetPathNode(MessagePath path)
{
if (!IsJson)
throw new InvalidOperationException("Can't access json data on non-json message");

var currentToken = _token;
foreach (var node in path)
{
Expand Down

0 comments on commit 61aa589

Please sign in to comment.