Component.cs 490 B

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