// Dictionaries & ArchivableDictionaries public static Dictionary <string, object> ToSpeckle(this ArchivableDictionary dict, Dictionary <int, string> traversed = null, string path = "root", GeometryBase root = null) { if (dict.Values.Length == 0) { return(null); } if (dict == null) { return(null); } if (traversed == null) { traversed = new Dictionary <int, string>(); traversed.Add(root.GetHashCode(), "root"); } Dictionary <string, object> myDictionary = new Dictionary <string, object>(); foreach (var key in dict.Keys) { var myObj = dict[key]; if (traversed.ContainsKey(myObj.GetHashCode())) { myDictionary.Add(key, new SpeckleAbstract() { _type = "ref", _ref = traversed[myObj.GetHashCode()] }); continue; } traversed.Add(myObj.GetHashCode(), path + "/" + key); if (dict[key] is ArchivableDictionary) { myDictionary.Add(key, (( ArchivableDictionary )dict[key]).ToSpeckle(traversed, path + "/" + key, root)); } else if (dict[key] is string || dict[key] is double || dict[key] is float || dict[key] is int || dict[key] is SpeckleObject) { myDictionary.Add(key, dict[key]); } else if (dict[key] is IEnumerable) { myDictionary.Add(key, "enums not supported yet."); } else { if (dict[key] is GeometryBase) { GeometryBase obj = dict[key] as GeometryBase; ArchivableDictionary dictCopy = obj.UserDictionary.Clone(); obj.UserDictionary.Clear(); SpeckleObject conv = SpeckleCore.Converter.Serialise(obj); conv.Properties = dictCopy.ToSpeckle(traversed, path + "/" + key, root); conv.GenerateHash(); myDictionary.Add(key, conv); obj.UserDictionary.ReplaceContentsWith(dictCopy); } else { myDictionary.Add(key, SpeckleCore.Converter.Serialise(dict[key])); } } } return(myDictionary); }