KVComponent.cs 657 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections.Generic;
  2. namespace Hotfix
  3. {
  4. /// <summary>
  5. /// Key Value组件用于保存一些数据
  6. /// </summary>
  7. public class KVComponent: Component
  8. {
  9. private readonly Dictionary<string, object> kv = new Dictionary<string, object>();
  10. public void Add(string key, object value)
  11. {
  12. this.kv.Add(key, value);
  13. }
  14. public void Remove(string key)
  15. {
  16. this.kv.Remove(key);
  17. }
  18. public T Get<T>(string key)
  19. {
  20. object k;
  21. if (!this.kv.TryGetValue(key, out k))
  22. {
  23. return default(T);
  24. }
  25. return (T) k;
  26. }
  27. public override void Dispose()
  28. {
  29. if (this.Id == 0)
  30. {
  31. return;
  32. }
  33. base.Dispose();
  34. }
  35. }
  36. }