diff --git a/ICD.Common.Utils/Extensions/JsonReaderExtensions.cs b/ICD.Common.Utils/Extensions/JsonReaderExtensions.cs index f99299e..82244fa 100644 --- a/ICD.Common.Utils/Extensions/JsonReaderExtensions.cs +++ b/ICD.Common.Utils/Extensions/JsonReaderExtensions.cs @@ -185,6 +185,44 @@ namespace ICD.Common.Utils.Extensions throw new InvalidCastException(message); } + /// + /// Gets the current value as a float. + /// + /// + /// + [PublicAPI] + public static float GetValueAsFloat([NotNull] this JsonReader extends) + { + if (extends == null) + throw new ArgumentNullException("extends"); + + if (extends.TokenType == JsonToken.Float || extends.TokenType == JsonToken.Integer) + return (float)extends.Value; + + string message = string.Format("Token {0} {1} is not {2}", extends.TokenType, extends.Value, + JsonToken.Integer); + throw new InvalidCastException(message); + } + + /// + /// Gets the current value as a double. + /// + /// + /// + [PublicAPI] + public static double GetValueAsDouble([NotNull] this JsonReader extends) + { + if (extends == null) + throw new ArgumentNullException("extends"); + + if (extends.TokenType == JsonToken.Float || extends.TokenType == JsonToken.Integer) + return (double)extends.Value; + + string message = string.Format("Token {0} {1} is not {2}", extends.TokenType, extends.Value, + JsonToken.Integer); + throw new InvalidCastException(message); + } + /// /// Gets the current value as a string. ///