Reduce boilerplate for writing to file

This commit is contained in:
Matt Nadareski
2020-08-28 15:06:07 -07:00
parent d11209951b
commit f85fbd68ce
18 changed files with 395 additions and 816 deletions

View File

@@ -336,6 +336,31 @@ namespace SabreTools.Library.DatFiles
return false;
}
/// <summary>
/// Get a list of filtered items for a given key
/// </summary>
/// <param name="key">Key in the dictionary to retrieve</param>
public List<DatItem> FilteredItems(string key)
{
lock (key)
{
// Get the list, if possible
List<DatItem> fi = items[key];
if (fi == null)
return new List<DatItem>();
// Filter the list
fi = fi.Where(i => i != null)
.Where(i => !i.Remove)
.Where(i => i.Name != null)
.Where(i => i.Machine?.Name != null)
.ToList();
// Return the list
return fi;
}
}
/// <summary>
/// Remove a key from the file dictionary if it exists
/// </summary>