feat: Extension method for reading JSON value as a UInt

This commit is contained in:
Chris Cameron
2018-04-11 15:32:04 -04:00
parent 27e3e55af4
commit 0eba82e3ef

View File

@@ -75,6 +75,24 @@ namespace ICD.Common.Utils.Extensions
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>
/// Gets the current value as an integer.
/// </summary>