Component.cs 818 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using MongoDB.Bson.Serialization.Attributes;
  3. namespace Common.Base
  4. {
  5. /// <summary>
  6. /// Component的Id与Owner Entity Id一样
  7. /// </summary>
  8. public abstract class Component<T>: Object where T: Entity<T>
  9. {
  10. private T owner;
  11. [BsonIgnore]
  12. public T Owner
  13. {
  14. protected get
  15. {
  16. return owner;
  17. }
  18. set
  19. {
  20. this.owner = value;
  21. this.Id = this.owner.Id;
  22. }
  23. }
  24. /// <summary>
  25. /// 用于父类的Component需要重写此方法
  26. /// </summary>
  27. /// <returns></returns>
  28. public virtual Type GetComponentType()
  29. {
  30. return this.GetType();
  31. }
  32. }
  33. }