private static List <Node> DataToNodeList(object data) { var objects = (List <object>)data; var nodes = new List <Node>(); foreach (var obj in objects) { if (obj == null) { continue; } nodes.Add(UnknownNode.Create((Dictionary <string, object>)obj)); } return(nodes); }
/// <summary> /// <see ref="QueryRoot" /> Accepts deserialized json data. /// <see ref="QueryRoot" /> Will further parse passed in data. /// </summary> /// <param name="dataJSON">Deserialized JSON data for QueryRoot</param> public QueryRoot(Dictionary <string, object> dataJSON) { DataJSON = dataJSON; Data = new Dictionary <string, object>(); foreach (string key in dataJSON.Keys) { string fieldName = key; Regex regexAlias = new Regex("^(.+)___.+$"); Match match = regexAlias.Match(key); if (match.Success) { fieldName = match.Groups[1].Value; } switch (fieldName) { case "articles": Data.Add( key, new ArticleConnection((Dictionary <string, object>)dataJSON[key]) ); break; case "blogByHandle": if (dataJSON[key] == null) { Data.Add(key, null); } else { Data.Add( key, new Blog((Dictionary <string, object>)dataJSON[key]) ); } break; case "blogs": Data.Add( key, new BlogConnection((Dictionary <string, object>)dataJSON[key]) ); break; case "collectionByHandle": if (dataJSON[key] == null) { Data.Add(key, null); } else { Data.Add( key, new Collection((Dictionary <string, object>)dataJSON[key]) ); } break; case "collections": Data.Add( key, new CollectionConnection((Dictionary <string, object>)dataJSON[key]) ); break; case "customer": if (dataJSON[key] == null) { Data.Add(key, null); } else { Data.Add( key, new Customer((Dictionary <string, object>)dataJSON[key]) ); } break; case "node": if (dataJSON[key] == null) { Data.Add(key, null); } else { Data.Add( key, UnknownNode.Create((Dictionary <string, object>)dataJSON[key]) ); } break; case "nodes": Data.Add( key, DataToNodeList(dataJSON[key]) ); break; case "pageByHandle": if (dataJSON[key] == null) { Data.Add(key, null); } else { Data.Add( key, new Page((Dictionary <string, object>)dataJSON[key]) ); } break; case "pages": Data.Add( key, new PageConnection((Dictionary <string, object>)dataJSON[key]) ); break; case "productByHandle": if (dataJSON[key] == null) { Data.Add(key, null); } else { Data.Add( key, new Product((Dictionary <string, object>)dataJSON[key]) ); } break; case "productTags": Data.Add( key, new StringConnection((Dictionary <string, object>)dataJSON[key]) ); break; case "productTypes": Data.Add( key, new StringConnection((Dictionary <string, object>)dataJSON[key]) ); break; case "products": Data.Add( key, new ProductConnection((Dictionary <string, object>)dataJSON[key]) ); break; case "shop": Data.Add( key, new Shop((Dictionary <string, object>)dataJSON[key]) ); break; } } }