diff --git a/SabreTools.DatFiles/DatFile.cs b/SabreTools.DatFiles/DatFile.cs index f0d45b13..07968068 100644 --- a/SabreTools.DatFiles/DatFile.cs +++ b/SabreTools.DatFiles/DatFile.cs @@ -158,41 +158,7 @@ namespace SabreTools.DatFiles /// /// Preconfigured filter runner to use public void ExecuteFilters(FilterRunner filterRunner) - { - List keys = [.. Items.Keys]; -#if NET452_OR_GREATER || NETCOREAPP - Parallel.ForEach(keys, Globals.ParallelOptions, key => -#elif NET40_OR_GREATER - Parallel.ForEach(keys, key => -#else - foreach (var key in keys) -#endif - { - ConcurrentList? items = Items[key]; - if (items == null) -#if NET40_OR_GREATER || NETCOREAPP - return; -#else - continue; -#endif - - // Filter all items in the current key - var newItems = new ConcurrentList(); - foreach (var item in items) - { - if (item.PassesFilter(filterRunner)) - newItems.Add(item); - } - - // Set the value in the key to the new set - Items[key] = newItems; - -#if NET40_OR_GREATER || NETCOREAPP - }); -#else - } -#endif - } + => Items.ExecuteFilters(filterRunner); #endregion diff --git a/SabreTools.DatFiles/ItemDictionary.cs b/SabreTools.DatFiles/ItemDictionary.cs index 29074d3c..dbbd2df0 100644 --- a/SabreTools.DatFiles/ItemDictionary.cs +++ b/SabreTools.DatFiles/ItemDictionary.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Xml.Serialization; using Newtonsoft.Json; using SabreTools.Core; +using SabreTools.Core.Filter; using SabreTools.DatItems; using SabreTools.DatItems.Formats; using SabreTools.Hashing; @@ -710,6 +711,51 @@ namespace SabreTools.DatFiles #endregion + #region Filtering + + /// + /// Execute all filters in a filter runner on the items in the dictionary + /// + /// Preconfigured filter runner to use + public void ExecuteFilters(FilterRunner filterRunner) + { + List keys = [.. Keys]; +#if NET452_OR_GREATER || NETCOREAPP + Parallel.ForEach(keys, Globals.ParallelOptions, key => +#elif NET40_OR_GREATER + Parallel.ForEach(keys, key => +#else + foreach (var key in keys) +#endif + { + ConcurrentList? items = this[key]; + if (items == null) +#if NET40_OR_GREATER || NETCOREAPP + return; +#else + continue; +#endif + + // Filter all items in the current key + var newItems = new ConcurrentList(); + foreach (var item in items) + { + if (item.PassesFilter(filterRunner)) + newItems.Add(item); + } + + // Set the value in the key to the new set + this[key] = newItems; + +#if NET40_OR_GREATER || NETCOREAPP + }); +#else + } +#endif + } + + #endregion + #region Statistics ///