mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-14 04:58:33 +00:00
refactor: Additional validation, tidying
This commit is contained in:
parent
ed299b8d4f
commit
48abd75d30
1 changed files with 19 additions and 6 deletions
|
|
@ -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)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
ReadProperty(property, reader, output, serializer);
|
ReadProperty(property, reader, output, serializer);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue