Entity.cs 701 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections.Generic;
  2. using Newtonsoft.Json;
  3. namespace Component
  4. {
  5. public class Entity
  6. {
  7. public int Id { get; set; }
  8. public Dictionary<string, object> Values { get; private set; }
  9. public Entity()
  10. {
  11. this.Values = new Dictionary<string, object>();
  12. }
  13. public object this[string key]
  14. {
  15. set
  16. {
  17. this.Values[key] = value;
  18. }
  19. get
  20. {
  21. return this.Values[key];
  22. }
  23. }
  24. public T Get<T>(string key)
  25. {
  26. if (!this.Values.ContainsKey(key))
  27. {
  28. throw new KeyNotFoundException(string.Format("not found key: {0}", key));
  29. }
  30. return (T)this.Values[key];
  31. }
  32. public bool Contain(string key)
  33. {
  34. return this.Values.ContainsKey(key);
  35. }
  36. }
  37. }