using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; using System.Collections.Generic; namespace F6 { public delegate bool TraverseCb(T ele); public interface IMetaTable { bool IsNoLoad() { return false; } void Load() { } void PreInit1() { } void ElementsInit(int round) { } void PostInit1() { } } public class RawMetaTable: IMetaTable { protected string fileName; protected string primKey; protected bool noLoad; protected List rawList = new List(); public void Traverse(TraverseCb cb) { foreach(var item in this.rawList) { if (!cb(item)) { break; } } } public T RandElement() { if (this.rawList.Count > 0) { return this.rawList[new Random().Next(0, this.rawList.Count)]; } return default(T); } public virtual void Load() { } protected virtual void LoadPost() { } } public class IdMetaTable: RawMetaTable { protected Dictionary idHash = new Dictionary (); public T GetById(Int64 id) { T v = default(T); this.idHash.TryGetValue(id, out v); return v; } protected override void LoadPost() { base.LoadPost(); } } public class NameMetaTable: RawMetaTable { protected Dictionary nameHash = new Dictionary(); public T GetByName(string key) { T v = default(T); this.nameHash.TryGetValue(key, out v); return v; } protected override void LoadPost() { base.LoadPost(); } } }