KVComponent.cs 651 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. if (!this.kv.TryGetValue(key, out object k))
  21. {
  22. return default(T);
  23. }
  24. return (T) k;
  25. }
  26. public override void Dispose()
  27. {
  28. if (this.Id == 0)
  29. {
  30. return;
  31. }
  32. base.Dispose();
  33. }
  34. }
  35. }