private static Dictionary <uint, ISaveable> buildObjectTable(ISaveable root, SaveType saveType) { Dictionary <uint, ISaveable> objects = new Dictionary <uint, ISaveable>(); objects.Add(root.GetId(), root); Stack <ISaveable> toVisit = new Stack <ISaveable>(); addUnvisitedSaveablesToStack(objects, root.GetSaveableRefs(saveType), toVisit); while (toVisit.Count != 0) { ISaveable next = toVisit.Pop(); if (objects.ContainsKey(next.GetId())) { throw new InvalidOperationException("Cannot add same object again"); } if (next.GetId() != VALUE_TYPE_ID) { objects.Add(next.GetId(), next); } List <ISaveable> refs = next.GetSaveableRefs(saveType); addUnvisitedSaveablesToStack(objects, refs, toVisit); } return(objects); }