public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var o = JObject.Load(reader); var dict = o.Properties().ToDictionary(p => p.Name, p => p.Value); if (!dict.HasAny()) { return(null); } IScriptTransform scriptTransform = null; if (dict.ContainsKey("inline")) { var inline = dict["inline"].ToString(); scriptTransform = new InlineScriptTransform(inline); } if (dict.ContainsKey("source")) { var inline = dict["source"].ToString(); scriptTransform = new InlineScriptTransform(inline); } if (dict.ContainsKey("file")) { var file = dict["file"].ToString(); scriptTransform = new FileScriptTransform(file); } if (dict.ContainsKey("id")) { var id = dict["id"].ToString(); scriptTransform = new IndexedScriptTransform(id); } if (scriptTransform == null) { return(null); } if (dict.ContainsKey("lang")) { scriptTransform.Lang = dict["lang"].ToString(); } if (dict.ContainsKey("params")) { scriptTransform.Params = dict["params"].ToObject <Dictionary <string, object> >(); } return(scriptTransform); }
public IScriptTransform Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { if (reader.GetCurrentJsonToken() != JsonToken.BeginObject) { return(null); } var count = 0; IScriptTransform scriptTransform = null; string language = null; Dictionary <string, object> parameters = null; while (reader.ReadIsInObject(ref count)) { if (AutomataDictionary.TryGetValue(reader.ReadPropertyNameSegmentRaw(), out var value)) { switch (value) { case 0: scriptTransform = new InlineScriptTransform(reader.ReadString()); break; case 1: scriptTransform = new IndexedScriptTransform(reader.ReadString()); break; case 2: language = reader.ReadString(); break; case 3: parameters = formatterResolver.GetFormatter <Dictionary <string, object> >() .Deserialize(ref reader, formatterResolver); break; } } } if (scriptTransform == null) { return(null); } scriptTransform.Lang = language; scriptTransform.Params = parameters; return(scriptTransform); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var o = JObject.Load(reader); var dict = o.Properties().ToDictionary(p => p.Name, p => p.Value); if (!dict.HasAny()) { return(null); } IScriptTransform scriptTransform = null; if (dict.TryGetValue("inline", out JToken inlineToken)) { var inline = inlineToken.ToString(); scriptTransform = new InlineScriptTransform(inline); } if (dict.TryGetValue("source", out JToken sourceToken)) { var inline = sourceToken.ToString(); scriptTransform = new InlineScriptTransform(inline); } if (dict.TryGetValue("id", out JToken idToken)) { var id = idToken.ToString(); scriptTransform = new IndexedScriptTransform(id); } if (scriptTransform == null) { return(null); } if (dict.TryGetValue("lang", out JToken langToken)) { scriptTransform.Lang = langToken.ToString(); } if (dict.TryGetValue("params", out JToken paramsToken)) { scriptTransform.Params = paramsToken.ToObject <Dictionary <string, object> >(); } return(scriptTransform); }