From 2e0837f5c8418fcd8ebe5f4667377f6076e204d7 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 24 Jan 2019 15:58:21 -0500 Subject: [PATCH] feat: Extension methods for reading current JSON token to the given type --- ICD.Common.Utils/Extensions/JsonExtensions.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ICD.Common.Utils/Extensions/JsonExtensions.cs b/ICD.Common.Utils/Extensions/JsonExtensions.cs index 5bffe77..38bfa59 100644 --- a/ICD.Common.Utils/Extensions/JsonExtensions.cs +++ b/ICD.Common.Utils/Extensions/JsonExtensions.cs @@ -36,6 +36,38 @@ namespace ICD.Common.Utils.Extensions jObject.WriteTo(extends, converter); } + /// + /// Reads the current token in the reader and deserializes to the given type. + /// + /// + /// + /// + public static T ReadAsObject(this JsonReader extends) + { + if (extends == null) + throw new ArgumentNullException("extends"); + + JsonSerializer serializer = new JsonSerializer(); + return extends.ReadAsObject(serializer); + } + + /// + /// Reads the current token in the reader and deserializes to the given type. + /// + /// + /// + /// + public static T ReadAsObject(this JsonReader extends, JsonSerializer serializer) + { + if (extends == null) + throw new ArgumentNullException("extends"); + + if (serializer == null) + throw new ArgumentNullException("serializer"); + + return serializer.Deserialize(extends); + } + /// /// Writes the type value. ///