17 using System.Collections.Generic;
18 using Newtonsoft.Json;
34 public override void WriteJson(JsonWriter writer,
object value, JsonSerializer serializer)
38 value =
new List<T> {(T)value};
40 serializer.Serialize(writer, value);
52 public override object ReadJson(JsonReader reader, Type objectType,
object existingValue, JsonSerializer serializer)
54 switch (reader.TokenType)
56 case JsonToken.String:
57 case JsonToken.StartObject:
58 return new List<T> {serializer.Deserialize<T>(reader)};
59 case JsonToken.StartArray:
60 return serializer.Deserialize<List<T>>(reader);
62 throw new ArgumentException(
"The JsonReader is expected to point at a JsonToken.StartObject or JsonToken.StartArray.");
73 return objectType == typeof(T) || objectType == typeof(List<T>);