17 using System.Globalization;
18 using Newtonsoft.Json;
19 using Newtonsoft.Json.Linq;
47 return typeof(
Order).IsAssignableFrom(objectType);
54 public override object ReadJson(JsonReader reader, Type objectType,
object existingValue, JsonSerializer serializer)
56 var token = JToken.ReadFrom(reader);
57 var jtokenType = token[
"Type"] ?? token[
"type"];
58 int orderType = GetOrderType(jtokenType);
59 if (token[
"Type"] !=
null)
61 token[
"Type"] = orderType;
63 else if (token[
"type"] !=
null)
65 token[
"type"] = orderType;
74 public override void WriteJson(JsonWriter writer,
object value, JsonSerializer serializer)
76 throw new NotImplementedException();
79 private int GetOrderType(JToken type)
81 var orderTypeValue = type.Value<
string>();
83 return Parse.
TryParse(orderTypeValue, NumberStyles.Any, out orderTypeNumber) ?