コード例 #1
0
        /// <summary>
        /// Removes a normal delegate from this weak multicast delegate
        /// </summary>
        /// <param name="realDelegate">the normal delegate</param>
        /// <returns>the new weak multicast delegate</returns>
        private WeakMulticastDelegate Remove(Delegate realDelegate)
        {
            if (Equals(realDelegate))
            {
                return(_prev);
            }

            WeakMulticastDelegate current = _prev;
            WeakMulticastDelegate last    = this;

            while (current != null)
            {
                if (current.Equals(realDelegate))
                {
                    last._prev    = current._prev;
                    current._prev = null;
                    break;
                }

                last    = current;
                current = current._prev;
            }

            return(this);
        }
コード例 #2
0
        /// <summary>
        /// Combines this weak multicast delegate with a normal delegate
        /// Makes sure the delegate target has not been added yet
        /// </summary>
        /// <param name="realDelegate">the real delegate</param>
        /// <returns>the new weak multicast delegate</returns>
        private WeakMulticastDelegate CombineUnique(Delegate realDelegate)
        {
            bool found = Equals(realDelegate);

            if (!found && _prev != null)
            {
                WeakMulticastDelegate curNode = _prev;

                while (!found && curNode != null)
                {
                    if (curNode.Equals(realDelegate))
                    {
                        found = true;
                    }

                    curNode = curNode._prev;
                }
            }

            return(found ? this : Combine(realDelegate));
        }