private static LinkItemCollection Parse(string json) { LinkItemCollection coll = new LinkItemCollection(); Dictionary <string, object>[] jsonItems = JsonConvert.DeserializeObject <Dictionary <string, object>[]>(json); LinkItemBase[] arrLinkItemBase = new LinkItemBase[jsonItems.Length]; //Execute this in parallel if possible to save time with json serialization/deserization for child items Parallel.ForEach(jsonItems, (x, state, index) => { Dictionary <string, object> dic = (Dictionary <string, object>)x; string linkType = dic["LinkTypeString"].ToString(); //HACK: Find a better way of doing this - we dont want to have to serialize/deserialize this again! //Need a good way of initially getting the array elements string json2 = JsonConvert.SerializeObject(dic); LinkItemBase itemBase = null; if (linkType == "Image") { itemBase = JsonConvert.DeserializeObject <ImageItem>(json2); } else if (linkType == "Internal") { itemBase = JsonConvert.DeserializeObject <InternalLinkItem>(json2); } else if (linkType == "External") { itemBase = JsonConvert.DeserializeObject <ExternalLinkItem>(json2); } else if (linkType == "Document") { itemBase = JsonConvert.DeserializeObject <DocumentItem>(json2); } else { if (PluginList != null) { ILinkItemCollectionPlugin plugin = PluginList.Find(y => y.Name == linkType); if (plugin != null) { itemBase = JsonConvert.DeserializeObject(json2, plugin.PluginType) as LinkItemBase; if (itemBase == null) { throw new Exception("The following json string for linkType " + linkType + " could not be parsed: " + json2); } } } } itemBase.SortOrder = (int)index; arrLinkItemBase[index] = itemBase; }); //Add the array items to the LinkItemCollection coll.AddRange(arrLinkItemBase); return(coll); }