Object.cs 731 B

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