using System; using System.Collections.Generic; using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Options; namespace ET { [Config] public partial class StartSceneConfigCategory : ConfigSingleton, IMerge { [BsonElement] [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] private Dictionary dict = new Dictionary(); public void Merge(object o) { StartSceneConfigCategory s = o as StartSceneConfigCategory; foreach (var kv in s.dict) { this.dict.Add(kv.Key, kv.Value); } } public StartSceneConfig Get(int id) { this.dict.TryGetValue(id, out StartSceneConfig item); if (item == null) { throw new Exception($"配置找不到,配置表名: {nameof (StartSceneConfig)},配置id: {id}"); } return item; } public bool Contain(int id) { return this.dict.ContainsKey(id); } public Dictionary GetAll() { return this.dict; } public StartSceneConfig GetOne() { if (this.dict == null || this.dict.Count <= 0) { return null; } return this.dict.Values.GetEnumerator().Current; } } public partial class StartSceneConfig: ProtoObject, IConfig { /// Id public int Id { get; set; } /// 所属进程 public int Process { get; set; } /// 所属区 public int Zone { get; set; } /// 类型 public string SceneType { get; set; } /// 名字 public string Name { get; set; } /// 外网端口 public int Port { get; set; } } }