Component.cs 654 B

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