Create and use Cleaner

This commit is contained in:
Matt Nadareski
2020-08-28 13:33:05 -07:00
parent 4e49dad4b7
commit 27bbc9df29
10 changed files with 258 additions and 256 deletions

View File

@@ -715,6 +715,28 @@ namespace SabreTools.Library.DatFiles
ClearEmpty();
}
/// <summary>
/// Remove any keys that have null or empty values
/// </summary>
public void ClearEmpty()
{
var keys = items.Keys.Where(k => k != null).ToList();
foreach (string key in keys)
{
// If the key doesn't exist, skip
if (!items.ContainsKey(key))
continue;
// If the value is null, remove
else if (items[key] == null)
items.Remove(key);
// If there are no non-blank items, remove
else if (items[key].Count(i => i != null && i.ItemType != ItemType.Blank) == 0)
items.Remove(key);
}
}
/// <summary>
/// Remove all items marked for removal
/// </summary>
@@ -829,22 +851,6 @@ namespace SabreTools.Library.DatFiles
});
}
/// <summary>
/// Remove any keys that have null or empty values
/// </summary>
private void ClearEmpty()
{
var keys = items.Keys.Where(k => k != null).ToList();
foreach (string key in keys)
{
if (!items.ContainsKey(key))
continue;
if (items[key] == null || items[key].Count == 0)
items.Remove(key);
}
}
/// <summary>
/// Get the highest-order Field value that represents the statistics
/// </summary>