Component.cs 525 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using MongoDB.Bson.Serialization.Attributes;
  2. namespace Model
  3. {
  4. [BsonIgnoreExtraElements]
  5. public abstract partial class Component: Disposer
  6. {
  7. [BsonIgnore]
  8. public Disposer Parent { get; set; }
  9. public T GetParent<T>() where T : Disposer
  10. {
  11. return this.Parent as T;
  12. }
  13. public Entity Entity
  14. {
  15. get
  16. {
  17. return this.Parent as Entity;
  18. }
  19. }
  20. protected Component()
  21. {
  22. this.Id = 1;
  23. }
  24. public override void Dispose()
  25. {
  26. if (this.Id == 0)
  27. {
  28. return;
  29. }
  30. base.Dispose();
  31. }
  32. }
  33. }