Object.cs 716 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.ComponentModel;
  3. using Base;
  4. using MongoDB.Bson.Serialization.Attributes;
  5. namespace Model
  6. {
  7. public abstract class Object: IDisposable, ISupportInitialize, ICloneable
  8. {
  9. [BsonId]
  10. [BsonIgnoreIfDefault]
  11. public long Id { get; private set; }
  12. protected Object()
  13. {
  14. Id = IdGenerater.GenerateId();
  15. }
  16. protected Object(long id)
  17. {
  18. this.Id = id;
  19. }
  20. public virtual void BeginInit()
  21. {
  22. }
  23. public virtual void EndInit()
  24. {
  25. }
  26. public override string ToString()
  27. {
  28. return MongoHelper.ToJson(this);
  29. }
  30. public virtual void Dispose()
  31. {
  32. this.Id = 0;
  33. }
  34. public object Clone()
  35. {
  36. return MongoHelper.FromJson(this.GetType(), this.ToString());
  37. }
  38. }
  39. }