17 using System.Collections.Generic;
18 using Newtonsoft.Json;
19 using Newtonsoft.Json.Linq;
44 public override void WriteJson(JsonWriter writer,
object? value, JsonSerializer serializer)
47 if (ReferenceEquals(parameterSet,
null))
return;
49 writer.WriteStartObject();
51 if (parameterSet.Value !=
null)
53 writer.WritePropertyName(
"parameterSet");
54 serializer.Serialize(writer, parameterSet.Value);
57 writer.WriteEndObject();
70 public override object ReadJson(JsonReader reader, Type objectType,
object existingValue, JsonSerializer serializer)
72 if (reader.TokenType == JsonToken.StartArray)
74 if (JArray.Load(reader).Count == 0)
76 return new ParameterSet(-1,
new Dictionary<string, string>());
79 else if (reader.TokenType == JsonToken.StartObject)
81 var jObject = JObject.Load(reader);
83 var value = jObject[
"parameterSet"] ?? jObject;
85 var parameterSet =
new ParameterSet(-1, value.ToObject<Dictionary<string, string>>());
90 throw new ArgumentException($
"Unexpected Tokentype {reader.TokenType}");