Disposer.cs 544 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using MongoDB.Bson.Serialization.Attributes;
  3. namespace Model
  4. {
  5. public abstract class Disposer : Object, IDisposable
  6. {
  7. [BsonIgnoreIfDefault]
  8. [BsonDefaultValue(1L)]
  9. [BsonElement]
  10. [BsonId]
  11. public long Id { get; set; }
  12. protected Disposer()
  13. {
  14. this.Id = IdGenerater.GenerateId();
  15. ObjectEvents.Instance.Add(this);
  16. }
  17. protected Disposer(long id)
  18. {
  19. this.Id = id;
  20. ObjectEvents.Instance.Add(this);
  21. }
  22. public virtual void Dispose()
  23. {
  24. this.Id = 0;
  25. ObjectPool.Instance.Recycle(this);
  26. }
  27. }
  28. }