コード例 #1
0
        public void On <E>(Action <E> callback)
        {
            if (EventIdentifiers == null)
            {
                EventIdentifiers = new List <Guid>();
            }

            var id = EventHub.On(callback);

            EventIdentifiers.Add(id);
        }
コード例 #2
0
        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);
            //}
        }