public void Disconnect(BaseComponent observedComponent)
 {
     if (ObservedComponents != null)
     {
         ObservedComponents.Remove(observedComponent);
     }
 }
        protected void DetachEvents()
        {
            if (IsDestroying || IsDisabling)
            {
                return;
            }

            IsDestroying = true;

            if (EventIdentifiers != null)
            {
                foreach (var id in EventIdentifiers)
                {
                    EventHub.Off(id);
                }

                EventIdentifiers.Clear();
            }

            // Detach observed components
            if (ObservedComponents != null)
            {
                foreach (var component in ObservedComponents)
                {
                    component.Off(this);
                }

                ObservedComponents.Clear();
            }

            // Detach subscribers
            if (Subscribers != null)
            {
                foreach (var subscriber in Subscribers)
                {
                    subscriber.Key.Disconnect(this);
                    subscriber.Value.Clear();
                }

                Subscribers.Clear();
            }

            //foreach (var e in GetType().GetEvents()) {
            //    e.ClearEvents(this);
            //}
        }
        public void On <E>(BaseComponent target, Action <E> callback)
        {
            if (target.Subscribers == null)
            {
                target.Subscribers = new Dictionary <BaseComponent, TypeRouter>();
            }

            if (ObservedComponents == null)
            {
                ObservedComponents = new List <BaseComponent>();
            }

            if (!target.Subscribers.ContainsKey(this))
            {
                target.Subscribers.Add(this, new TypeRouter());
            }

            ObservedComponents.Add(target);
            target.Subscribers[this].On(callback);
        }