using System; using System.Collections.Generic; using System.Linq; namespace NBF.ConfigTable; public interface IConfigContext { // 定义非泛型接口 } public class ConfigContext : IConfigContext where T : IConfigTable { private static List _cacheList = new List(); #region Cache public void Association(List list) { if (list != null) { _cacheList = list; } } #endregion public int Count() { return _cacheList.Count; } public int Count(Func predicate) { return _cacheList.Count(predicate); } public T Get(uint key) { return First(key); } public T Fist() { return _cacheList.First(); } public T Last() { return _cacheList.Last(); } public T Fist(Predicate match) { return Get(match); } public T Last(Predicate match) { return _cacheList.FindLast(match); } public T Get(Predicate match) { return _cacheList.Find(match); } public T GetRandom() { Random random = new Random(); // 随机从列表中取一个对象 return _cacheList[random.Next(_cacheList.Count)]; } public List GetList() { return _cacheList; } public List GetList(Predicate match) { return _cacheList.FindAll(match); } private T First(uint key) { return _cacheList.Find(t => t.Key == key); } }