From 48abd75d30a163a127441a019804c488d25eb58f Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Sun, 9 Sep 2018 14:13:48 -0400 Subject: [PATCH] refactor: Additional validation, tidying --- .../Json/AbstractGenericJsonConverter.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/ICD.Common.Utils/Json/AbstractGenericJsonConverter.cs b/ICD.Common.Utils/Json/AbstractGenericJsonConverter.cs index ced8956..a6ea772 100644 --- a/ICD.Common.Utils/Json/AbstractGenericJsonConverter.cs +++ b/ICD.Common.Utils/Json/AbstractGenericJsonConverter.cs @@ -47,6 +47,18 @@ namespace ICD.Common.Utils.Json [PublicAPI] public virtual void WriteJson(JsonWriter writer, T value, JsonSerializer serializer) { + if (writer == null) + throw new ArgumentNullException("writer"); + + if (serializer == null) + throw new ArgumentNullException("serializer"); + + if (value == null) + { + writer.WriteNull(); + return; + } + writer.WriteStartObject(); { WriteProperties(writer, value, serializer); @@ -98,6 +110,12 @@ namespace ICD.Common.Utils.Json [PublicAPI] public virtual T ReadJson(JsonReader reader, T existingValue, JsonSerializer serializer) { + if (reader == null) + throw new ArgumentNullException("reader"); + + if (serializer == null) + throw new ArgumentNullException("serializer"); + T output = default(T); bool instantiated = false; @@ -120,12 +138,7 @@ namespace ICD.Common.Utils.Json // Read into the value reader.Read(); - switch (property) - { - default: - ReadProperty(property, reader, output, serializer); - break; - } + ReadProperty(property, reader, output, serializer); } return output;