Object.cs 766 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.ComponentModel;
  3. using MongoDB.Bson.Serialization.Attributes;
  4. namespace Base
  5. {
  6. public abstract class Object: IDisposable, ISupportInitialize
  7. {
  8. [BsonIgnore]
  9. public static ObjectManager ObjectManager = new ObjectManager();
  10. [BsonId]
  11. public long Id { get; private set; }
  12. protected Object()
  13. {
  14. Id = IdGenerater.GenerateId();
  15. ObjectManager.Add(this);
  16. }
  17. protected Object(long id)
  18. {
  19. this.Id = id;
  20. ObjectManager.Add(this);
  21. }
  22. public bool IsDisposed()
  23. {
  24. return this.Id == 0;
  25. }
  26. public virtual void Dispose()
  27. {
  28. if (this.Id == 0)
  29. {
  30. return;
  31. }
  32. ObjectManager.Remove(this.Id);
  33. this.Id = 0;
  34. }
  35. public virtual void BeginInit()
  36. {
  37. }
  38. public virtual void EndInit()
  39. {
  40. }
  41. }
  42. }