mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 21:24:58 +00:00
feat: Extension method for reading JSON value as a UInt
This commit is contained in:
@@ -75,6 +75,24 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
return Type.GetType(value);
|
return Type.GetType(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current value as an unsigned integer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="extends"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[PublicAPI]
|
||||||
|
public static uint GetValueAsUInt(this JsonReader extends)
|
||||||
|
{
|
||||||
|
if (extends == null)
|
||||||
|
throw new ArgumentNullException("extends");
|
||||||
|
|
||||||
|
if (extends.TokenType == JsonToken.Integer)
|
||||||
|
return (uint)(long)extends.Value;
|
||||||
|
|
||||||
|
string message = string.Format("Token {0} {1} is not {2}", extends.TokenType, extends.Value, JsonToken.Integer);
|
||||||
|
throw new InvalidCastException(message);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current value as an integer.
|
/// Gets the current value as an integer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user