Refactor MemoryCacheExtensions and HistoryController
Updated MemoryCacheExtensions to accept more flexible parameters in GetEnumAsDictionary and improved the merging logic for ignored values. Simplified HistoryController by removing the logger dependency and adjusted GetReferenceTypes to include a key parameter for cache retrieval.
This commit is contained in:
@@ -6,11 +6,20 @@ public static class MemoryCacheExtensions
|
||||
{
|
||||
private static readonly Guid BaseId = Guid.NewGuid();
|
||||
|
||||
public static IDictionary<string, int> GetEnumAsDictionary<TEnum>(this IMemoryCache memoryCache, string key = "", params IEnumerable<TEnum>[] ignores)
|
||||
public static IDictionary<string, int> GetEnumAsDictionary<TEnum>(this IMemoryCache memoryCache, string key = "", params object[] ignores)
|
||||
where TEnum : Enum
|
||||
=> memoryCache.GetOrCreate(BaseId + typeof(TEnum).FullName + key, _ =>
|
||||
{
|
||||
List<TEnum> mergedIgnores = ignores.SelectMany(x => x).ToList();
|
||||
var mergedIgnores = new List<TEnum>();
|
||||
|
||||
foreach (var ignore in ignores)
|
||||
{
|
||||
if (ignore is IEnumerable<TEnum> ignoreList)
|
||||
mergedIgnores.AddRange(ignoreList);
|
||||
else if (ignore is TEnum ignoreVal)
|
||||
mergedIgnores.Add(ignoreVal);
|
||||
}
|
||||
|
||||
return Enum.GetValues(typeof(TEnum))
|
||||
.Cast<TEnum>()
|
||||
.Where(e => !mergedIgnores.Contains(e))
|
||||
|
||||
Reference in New Issue
Block a user