public static ASTerm Parse(JObject obj) { if (obj.Properties().Any(a => !a.Name.StartsWith("@"))) { return new ASTerm { SubObject = ASObject.Parse(obj) } } ; else if (obj["@id"] != null) { return new ASTerm { Id = obj["@id"].ToObject <string>() } } ; else if (obj["@type"] != null && obj["@value"] != null) { return new ASTerm { Primitive = obj["@value"].ToObject <object>(), Type = obj["@type"].ToObject <string>() } } ; else if (obj["@value"] != null) { return new ASTerm { Primitive = obj["@value"].ToObject <object>() } } ; return(new ASTerm { SubObject = ASObject.Parse(obj) }); }
private void _deserialize(string arg, JToken val) { if (val.Type == JTokenType.Array) { foreach (var v in val.Value <JArray>()) { _deserialize(arg, v); } } else { var arr = this[arg]; if (val.Type == JTokenType.Object) { arr.Add(new ASTerm { SubObject = ASObject.Parse(val.Value <JObject>()) }); } else if (val.Type == JTokenType.Float) { arr.Add(new ASTerm { Primitive = val.Value <decimal>() }); } else if (val.Type == JTokenType.Integer) { arr.Add(new ASTerm { Primitive = val.Value <int>() }); } else if (val.Type == JTokenType.Boolean) { arr.Add(new ASTerm { Primitive = val.Value <bool>() }); } else { arr.Add(new ASTerm { Primitive = val.Value <string>() }); } } }