Object.cs 655 B

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