using System; using System.Collections.Generic; using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Options; namespace ET { [Config] public partial class UnitConfigCategory : ConfigSingleton, IMerge { [BsonElement] [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] private Dictionary dict = new Dictionary(); public void Merge(object o) { UnitConfigCategory s = o as UnitConfigCategory; foreach (var kv in s.dict) { this.dict.Add(kv.Key, kv.Value); } } public UnitConfig Get(int id) { this.dict.TryGetValue(id, out UnitConfig item); if (item == null) { throw new Exception($"配置找不到,配置表名: {nameof (UnitConfig)},配置id: {id}"); } return item; } public bool Contain(int id) { return this.dict.ContainsKey(id); } public Dictionary GetAll() { return this.dict; } public UnitConfig GetOne() { if (this.dict == null || this.dict.Count <= 0) { return null; } return this.dict.Values.GetEnumerator().Current; } } public partial class UnitConfig: ProtoObject, IConfig { /// Id public int Id { get; set; } /// Type public int Type { get; set; } /// 名字 public string Name { get; set; } /// 位置 public int Position { get; set; } /// 体重 public int Weight { get; set; } } }