Component.cs 580 B

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