升级.net8

This commit is contained in:
dell
2024-11-14 09:01:55 +08:00
parent 48e9e27fa0
commit abf72c3d58
86 changed files with 14229 additions and 10612 deletions

View File

@ -212,16 +212,33 @@ namespace HT.Cloud.Code
/// <returns></returns>
public static List<string> GetCacheKeys()
{
const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
var entries = Cache.GetType().GetField("_entries", flags).GetValue(Cache);
var cacheItems = entries as IDictionary;
var keys = new List<string>();
if (cacheItems == null) return keys;
foreach (DictionaryEntry cacheItem in cacheItems)
{
keys.Add(cacheItem.Key.ToString());
}
return keys;
}
}
#if NET8_0
const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
var entries = Cache.GetType().GetField("_coherentState", flags)?.GetValue(Cache);
var cacheItems = entries?.GetType()?.GetProperty("EntriesCollection", flags)?.GetValue(entries) as ICollection; //entries as IDictionary;
var keys = new List<string>();
if (cacheItems == null) return keys;
foreach (var item in cacheItems)
{
var methodInfo = item.GetType().GetProperty("Key");
var val = methodInfo.GetValue(item);
keys.Add(val.ToString());
}
return keys;
#else
const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
var entries = Cache.GetType().GetField("_entries", flags).GetValue(Cache);
var cacheItems = entries as IDictionary;
var keys = new List<string>();
if (cacheItems == null) return keys;
foreach (DictionaryEntry cacheItem in cacheItems)
{
keys.Add(cacheItem.Key.ToString());
}
return keys;
#endif
}
}
}