parent
74ca11e309
commit
b1651c89c6
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Common
|
||||
{
|
||||
public static class JsonNetExtensions
|
||||
{
|
||||
public static JEnumerable<T> Children<T>(this JToken token, string key)
|
||||
where T : JToken
|
||||
{
|
||||
return token[key]?.Children<T>() ?? JEnumerable<T>.Empty;
|
||||
}
|
||||
|
||||
public static T ValueOrThrow<T>(this JToken token, string key)
|
||||
where T : class
|
||||
{
|
||||
var value = token.Value<T>(key);
|
||||
if (value is null)
|
||||
{
|
||||
throw new ArgumentNullException(token.Path);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue