using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ET { public abstract class ACategory : ET.Object { public abstract Type ConfigType { get; } public abstract IConfig GetOne(); public abstract void LoadAsync(); public abstract IEnumerable GetAll(); public abstract IConfig TryGet(long type) ; } /// /// 管理该所有的配置 /// /// public abstract class ACategory : ACategory where T : IConfig { protected Dictionary dict; public override void BeginInit() { } public override void LoadAsync() { try { string str = ConfigHelper.GetText(typeof(T).Name); this.dict = ConfigHelper.ToObject>(str); } catch (Exception e) { throw new Exception($"parser json fail: {typeof(T).Name}", e); } } public override Type ConfigType => typeof(T); public override void EndInit() { } public override IConfig TryGet(long type) { if (!this.dict.TryGetValue(type, out T t)) { return null; } return t; } public T Get(long id,bool canError =true) { if (!this.dict.TryGetValue(id, out T t)&& canError) { Log.Error($"config == null which type = {GetType()} when id = {id}"); return default; } return t; } public override IEnumerable GetAll() { return this.dict.Values as IEnumerable; } public override IConfig GetOne() { return this.dict.Values.First(); } } }