Ejemplo n.º 1
0
        private WeakSubscription FindSubscription(Delegate handler)
        {
            // Get the target
            var target = handler.Target;

            // Get the new info
            var method = handler.GetMethodInfo();

            // Make sure it's not already subscribed
            for (var iSub = _subscriptions.Count - 1; iSub >= 0; iSub--)
            {
                // Get the subscription
                var sub = _subscriptions[iSub];

                // Subscriber still alive?
                if (sub.Instance.IsAlive)
                {
                    // Already subscribed?
                    if ((sub.Instance.Target == target) && (Equals(sub.Method, method)))
                    {
                        return(sub);
                    }
                }
                else
                {
                    // Reference dead. Might as well remove it.
                    _subscriptions.RemoveAt(iSub);
                }
            }

            // Not found
            return(null);
        }
Ejemplo n.º 2
0
        private WeakSubscription FindSubscription(Delegate handler)
        {
            // Get the target
            var target = handler.Target;

            // Get the new info
            var method = handler.GetMethodInfo();

            // Make sure it's not already subscribed
            for (int iSub = subscriptions.Count - 1; iSub >= 0; iSub--)
            {
                // Get the subscription
                var sub = subscriptions[iSub];

                // Subscriber still alive?
                if (sub.Instance.IsAlive)
                {
                    // Already subscribed?
                    if ((sub.Instance.Target == target) && (sub.Method == method))
                    {
                        return(sub);
                    }
                }
                else
                {
                    // Reference dead. Might as well remove it.
                    subscriptions.RemoveAt(iSub);
                    #if WEAK_LOGGING
                    Debug.WriteLine(string.Format("Removing expired registration for event '{0}' and object ID {1}. New total registrations: {2}", eventName, source.Target.GetHashCode(), registrations.Count));
                    #endif
                }
            }

            // Not found
            return(null);
        }