Component.cs 575 B

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