diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 7cc18bb6..1eff376f 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -1435,12 +1435,6 @@ namespace SabreTools.Library.DatFiles i--; // This make sure that the pointer stays on the correct since one was removed } } - - // Now remove the old key (if different than the current key) - if (!currentkey) - { - Remove(key); - } } } @@ -1472,6 +1466,9 @@ namespace SabreTools.Library.DatFiles AddRange(key, sortedlist); }); } + + // Now clean up all empty keys + CleanEmptyKeys(); } /// @@ -1558,6 +1555,21 @@ namespace SabreTools.Library.DatFiles return key; } + /// + /// Clean out all empty keys in the dictionary + /// + private void CleanEmptyKeys() + { + List keys = Keys; + foreach(string key in keys) + { + if (this[key].Count == 0) + { + Remove(key); + } + } + } + #endregion #region Constructors