using System.Collections.Generic; namespace TyphoonPool { /// /// 对象池分组 /// public class PoolGroup { public readonly Dictionary Pools = new Dictionary(); //批量添加 public void AddRange(params (TKey key, Pool value)[] pairs) { foreach (var pair in pairs) { Pools.Add(pair.key, pair.value); } } //添加池 public void AddPool(TKey key, Pool pool) { Pools.Add(key, pool); } //移除池 public void RemovePool(TKey key) { Pools.Remove(key); } public Pool GetPool(TKey key) { return Pools[key]; } public Pool GetPoolOrDefault(TKey key) { if (Pools.TryGetValue(key, out var match)) { return match; } return null; } public bool HasPool(TKey key) { return Pools.ContainsKey(key); } public IPoolObject GetPoolObject(TKey key) { return GetPool(key).GetPoolObject(); } public T GetPoolObjectAs(TKey key) where T : IPoolObject { return GetPool(key).GetPoolObjectAs(); } } }