StartZoneConfig.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using MongoDB.Bson.Serialization.Attributes;
  4. using ProtoBuf;
  5. namespace ET
  6. {
  7. [ProtoContract]
  8. [Config]
  9. public partial class StartZoneConfigCategory : ProtoObject
  10. {
  11. public static StartZoneConfigCategory Instance;
  12. [ProtoIgnore]
  13. [BsonIgnore]
  14. private Dictionary<int, StartZoneConfig> dict = new Dictionary<int, StartZoneConfig>();
  15. [BsonElement]
  16. [ProtoMember(1)]
  17. private List<StartZoneConfig> list = new List<StartZoneConfig>();
  18. public StartZoneConfigCategory()
  19. {
  20. Instance = this;
  21. }
  22. public override void AfterDeserialization()
  23. {
  24. foreach (StartZoneConfig config in list)
  25. {
  26. this.dict.Add(config.Id, config);
  27. }
  28. list.Clear();
  29. base.AfterDeserialization();
  30. }
  31. public StartZoneConfig Get(int id)
  32. {
  33. this.dict.TryGetValue(id, out StartZoneConfig item);
  34. if (item == null)
  35. {
  36. throw new Exception($"配置找不到,配置表名: {nameof (StartZoneConfig)},配置id: {id}");
  37. }
  38. return item;
  39. }
  40. public bool Contain(int id)
  41. {
  42. return this.dict.ContainsKey(id);
  43. }
  44. public Dictionary<int, StartZoneConfig> GetAll()
  45. {
  46. return this.dict;
  47. }
  48. public StartZoneConfig GetOne()
  49. {
  50. if (this.dict == null || this.dict.Count <= 0)
  51. {
  52. return null;
  53. }
  54. return this.dict.Values.GetEnumerator().Current;
  55. }
  56. }
  57. [ProtoContract]
  58. public partial class StartZoneConfig: IConfig
  59. {
  60. [ProtoMember(1, IsRequired = true)]
  61. public int Id { get; set; }
  62. [ProtoMember(2, IsRequired = true)]
  63. public string DBConnection { get; set; }
  64. [ProtoMember(3, IsRequired = true)]
  65. public string DBName { get; set; }
  66. }
  67. }