Esempio n. 1
0
        // This method currently looks backward on the invocation list
        //	for an element that has Delegate based equality with value.  (Doesn't
        //	look at the invocation list.)  If this is found we remove it from
        //	this list and return a new delegate.  If its not found a copy of the
        //	current list is returned.
        /// <include file='doc\MulticastDelegate.uex' path='docs/doc[@for="MulticastDelegate.RemoveImpl"]/*' />
        protected override sealed Delegate RemoveImpl(Delegate value)
        {
            // There is a special case were we are removing using a delegate as
            //	the value we need to check for this case
            //
            if (!(value is MulticastDelegate))
            {
                if (base.Equals(value))
                {
                    return(_prev);
                }
                return(this);
            }

            // Look for the delegate...
            MulticastDelegate v = (MulticastDelegate)value;

            if (InternalEquals(v))
            {
                int size            = v.DelSize();
                MulticastDelegate p = _prev;
                while (--size != 0)
                {
                    p = p._prev;
                }
                return(p);
            }

            MulticastDelegate d    = (MulticastDelegate)this.MemberwiseClone();
            MulticastDelegate root = d;

            while (d._prev != null && d._prev.InternalEquals(v) != true)
            {
                d._prev = (MulticastDelegate)d._prev.MemberwiseClone();
                d       = d._prev;
            }

            if (d._prev != null)
            {
                int size            = v.DelSize();
                MulticastDelegate p = d._prev._prev;
                while (--size != 0)
                {
                    p = p._prev;
                }
                d._prev = p;
            }
            return(root);
        }