mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
refactor: Additional validation, tidying
This commit is contained in:
@@ -47,6 +47,18 @@ namespace ICD.Common.Utils.Json
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public virtual void WriteJson(JsonWriter writer, T value, JsonSerializer serializer)
|
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();
|
writer.WriteStartObject();
|
||||||
{
|
{
|
||||||
WriteProperties(writer, value, serializer);
|
WriteProperties(writer, value, serializer);
|
||||||
@@ -98,6 +110,12 @@ namespace ICD.Common.Utils.Json
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public virtual T ReadJson(JsonReader reader, T existingValue, JsonSerializer serializer)
|
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);
|
T output = default(T);
|
||||||
bool instantiated = false;
|
bool instantiated = false;
|
||||||
|
|
||||||
@@ -120,12 +138,7 @@ namespace ICD.Common.Utils.Json
|
|||||||
// Read into the value
|
// Read into the value
|
||||||
reader.Read();
|
reader.Read();
|
||||||
|
|
||||||
switch (property)
|
ReadProperty(property, reader, output, serializer);
|
||||||
{
|
|
||||||
default:
|
|
||||||
ReadProperty(property, reader, output, serializer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|||||||
Reference in New Issue
Block a user