using MongoDB.Bson.Serialization.Attributes; namespace Model { [BsonKnownTypes(typeof(ComponentDB))] public abstract class Component: Disposer { [BsonIgnore] public Entity Owner { get; set; } public T GetOwner() where T : Entity { return this.Owner as T; } protected Component() { ObjectEvents.Instance.Add(this); } protected Component(long id): base(id) { ObjectEvents.Instance.Add(this); } public T GetComponent() where T : Component { return this.Owner.GetComponent(); } public override void Dispose() { if (this.Id == 0) { return; } base.Dispose(); this.Owner.RemoveComponent(this.GetType()); ObjectEvents.Instance.Remove(this); } public override void EndInit() { base.EndInit(); ObjectEvents.Instance.Add(this); } } }