Object.cs 643 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.ComponentModel;
  3. using MongoDB.Bson;
  4. using MongoDB.Bson.Serialization.Attributes;
  5. namespace Model
  6. {
  7. public abstract class Object: ISupportInitialize, ICloneable
  8. {
  9. [BsonId]
  10. [BsonIgnoreIfDefault]
  11. public long Id { get; protected 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 this.ToJson();
  29. }
  30. public object Clone()
  31. {
  32. return MongoHelper.FromBson(this.GetType(), this.ToBson());
  33. }
  34. }
  35. }