Equals() public method

public Equals ( object obj ) : bool
obj object
return bool
Beispiel #1
0
        private bool InvocationListEquals(MulticastDelegate d)
        {
            Debug.Assert(d != null);
            Debug.Assert(_invocationList is object[]);
            object[] invocationList = (object[])_invocationList;

            if (d._invocationCount != _invocationCount)
            {
                return(false);
            }

            int invocationCount = (int)_invocationCount;

            for (int i = 0; i < invocationCount; i++)
            {
                Debug.Assert(invocationList[i] is Delegate);
                Delegate dd = (Delegate)invocationList[i]; // If invocationList is an object[], it always contains Delegate (or MulticastDelegate) objects

                object[] dInvocationList = (d._invocationList as object[]) !;
                if (!dd.Equals(dInvocationList[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Remove the given delegate from my invocation list.
        /// </summary>
        protected override sealed Delegate Remove(Delegate other)
        {
            if (this.Equals(other))
            {
                // Front of the list
                var result = next;
                next = null;
                return(result);
            }

            MulticastDelegate parent = this;

            while ((parent != null) && (!other.Equals(parent.next)))
            {
                parent = parent.next;
            }

            if (parent != null)
            {
                MulticastDelegate otherx = parent.next;
                parent.next = otherx.next;
                otherx.next = null;
            }

            return(this);
        }
Beispiel #3
0
        /// <summary>
        /// Remove the given delegate from my invocation list.
        /// </summary>
        protected override sealed Delegate Remove(Delegate other)
        {
            if (this.Equals(other))
            {
                // Front of the list
                var result = next;
                next = null;
                return result;
            }

            MulticastDelegate parent = this;
            while ((parent != null) && (!other.Equals(parent.next)))
            {
                parent = parent.next;
            }

            if (parent != null)
            {
                MulticastDelegate otherx = parent.next;
                parent.next = otherx.next;
                otherx.next = null;
            }

            return this;
        }
 public void RemoveListener(Delegate listener)
 {
     this.listeners.RemoveAll(reference => {
         //Remove the listener, and prune collected listeners
         Delegate target = reference.Target;
         return listener.Equals(target) || target == null;
     });
 }
Beispiel #5
0
 protected virtual Delegate RemoveImpl(Delegate d)
 {
     if (!d.Equals(this))
     {
         return(this);
     }
     return(null);
 }
Beispiel #6
0
 public void RemoveListener(Delegate listener)
 {
     _listeners.RemoveAll(reference =>
     {
         var local0 = reference.Target;
         if (!listener.Equals(local0))
             return local0 == null;
         return true;
     });
 }
        public void RemoveListener(Delegate listener)
        {
            if (listener == null) throw new ArgumentNullException("listener");
            Contract.EndContractBlock();

            this.listeners.RemoveAll(reference =>
            {
                //Remove the listener, and prune collected listeners
                Delegate target = reference.Target;
                return listener.Equals(target) || target == null;
            });
        }
Beispiel #8
0
 static new public int Equals(IntPtr l)
 {
     try {
         System.Delegate self = (System.Delegate)checkSelf(l);
         System.Object   a1;
         checkType(l, 2, out a1);
         var ret = self.Equals(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    static int Equals(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 2);
            System.Delegate obj  = (System.Delegate)ToLua.CheckObject <System.Delegate>(L, 1);
            object          arg0 = ToLua.ToVarObject(L, 2);
            bool            o    = obj != null?obj.Equals(arg0) : arg0 == null;

            LuaDLL.lua_pushboolean(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Beispiel #10
0
    static int Equals(IntPtr L)
    {
        ToLua.CheckArgsCount(L, 2);
        System.Delegate obj  = (System.Delegate)ToLua.CheckObject(L, 1, typeof(System.Delegate));
        object          arg0 = ToLua.ToVarObject(L, 2);
        bool            o;

        try
        {
            o = obj != null?obj.Equals(arg0) : arg0 == null;
        }
        catch (Exception e)
        {
            return(LuaDLL.luaL_error(L, e.Message));
        }

        LuaDLL.lua_pushboolean(L, o);
        return(1);
    }
        private bool InvocationListEquals(MulticastDelegate d)
        {
            object[] objArray = this._invocationList as object[];
            if (d._invocationCount != this._invocationCount)
            {
                return(false);
            }
            int num = (int)this._invocationCount;

            for (int i = 0; i < num; i++)
            {
                Delegate delegate2 = (Delegate)objArray[i];
                object[] objArray2 = d._invocationList as object[];
                if (!delegate2.Equals(objArray2[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #12
0
        private bool InvocationListEquals(MulticastDelegate d)
        {
            Delegate[] invocationList = m_helperObject as Delegate[];
            if (d.m_extraFunctionPointerOrData != m_extraFunctionPointerOrData)
            {
                return(false);
            }

            int invocationCount = (int)m_extraFunctionPointerOrData;

            for (int i = 0; i < invocationCount; i++)
            {
                Delegate   dd = invocationList[i];
                Delegate[] dInvocationList = d.m_helperObject as Delegate[];
                if (!dd.Equals(dInvocationList[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #13
0
        // Recursive function which will check for equality of the invocation list.
        private bool InvocationListEquals(MulticastDelegate d)
        {
            Debug.Assert(d != null && (_invocationList as Object[]) != null, "bogus delegate in multicast list comparison");
            Object[] invocationList = _invocationList as Object[];
            if (d._invocationCount != _invocationCount)
            {
                return(false);
            }

            int invocationCount = (int)_invocationCount;

            for (int i = 0; i < invocationCount; i++)
            {
                Delegate dd = (Delegate)invocationList[i];
                Object[] dInvocationList = d._invocationList as Object[];
                if (!dd.Equals(dInvocationList[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #14
0
 protected virtual Delegate RemoveImpl(Delegate d)
 {
     return((d.Equals(this)) ? null : this);
 }
 protected sealed override Delegate RemoveImpl(Delegate value)
 {
     MulticastDelegate delegate2 = value as MulticastDelegate;
     if (delegate2 != null)
     {
         if (delegate2._invocationList is object[])
         {
             object[] a = this._invocationList as object[];
             if (a != null)
             {
                 int invocationCount = (int) this._invocationCount;
                 int count = (int) delegate2._invocationCount;
                 for (int i = invocationCount - count; i >= 0; i--)
                 {
                     if (this.EqualInvocationLists(a, delegate2._invocationList as object[], i, count))
                     {
                         if ((invocationCount - count) == 0)
                         {
                             return null;
                         }
                         if ((invocationCount - count) == 1)
                         {
                             return (Delegate) a[(i != 0) ? 0 : (invocationCount - 1)];
                         }
                         object[] invocationList = this.DeleteFromInvocationList(a, invocationCount, i, count);
                         return this.NewMulticastDelegate(invocationList, invocationCount - count, true);
                     }
                 }
             }
         }
         else
         {
             object[] objArray = this._invocationList as object[];
             if (objArray == null)
             {
                 if (this.Equals(value))
                 {
                     return null;
                 }
             }
             else
             {
                 int num = (int) this._invocationCount;
                 int index = num;
                 while (--index >= 0)
                 {
                     if (value.Equals(objArray[index]))
                     {
                         if (num == 2)
                         {
                             return (Delegate) objArray[1 - index];
                         }
                         object[] objArray2 = this.DeleteFromInvocationList(objArray, num, index, 1);
                         return this.NewMulticastDelegate(objArray2, num - 1, true);
                     }
                 }
             }
         }
     }
     return this;
 }
		protected sealed override Delegate RemoveImpl (Delegate removed)
		{
			if (removed == null)
				return this;

		    var removedMulticast = removed as MulticastDelegate;
		    if (removedMulticast == null || removedMulticast.invocationList == null)
		    {
		        if (invocationList == null)
		        {
                    // Both non multicast Delegate, so nothing left
		            if (base.Equals(removed))
		                return null;
		        }
		        else
		        {
                    // Remove from list
		            int invocationCount = invocationList.Length;
		            for (int i = invocationCount; --i >= 0;)
		            {
		                if (removed.Equals(invocationList[i]))
		                {
                            // Only two delegates?
                            // Returns the other one
		                    if (invocationCount == 2)
		                        return invocationList[1 - i];

		                    var newInvocationList = new Delegate[invocationCount - 1];
		                    
                            int j;
                            for (j = 0; j < i; j++)
                                newInvocationList[j] = invocationList[j];
                            for (j++; j < invocationCount; j++)
                                newInvocationList[j - 1] = invocationList[j];

                            return NewMulticast(newInvocationList);
		                }
		            }
		        }
		    }
		    else
		    {
		        var removedInvocationList = removedMulticast.invocationList;
                var removedInvocationCount = removedInvocationList.Length;

                // Removing a multicast delegate from a delegate wouldn't make sense, only consider the case
                // where we remove a multicast from a multicast
		        if (invocationList != null)
		        {
                    int invocationCount = invocationList.Length;

                    // Iterate over every possible range
                    // TODO: KPM?
		            for (int startIndex = invocationCount - removedInvocationCount; startIndex >= 0; --startIndex)
		            {
                        // Compare ranges
		                var equal = true;
		                for (int i = 0; i < removedInvocationCount; i++)
		                {
		                    if (!(invocationList[startIndex + i].Equals(removedInvocationList[i])))
		                    {
		                        equal = false;
		                        break;
		                    }
		                }

		                if (!equal)
                            continue; // Try startIndex - 1

                        // We have a match
		                var leftInvocationCount = invocationCount - removedInvocationCount;

                        // Nothing left?
                        if (leftInvocationCount == 0)
                            return null;

                        // Only one value left? (last or first)
                        if (leftInvocationCount == 1)
                            return invocationList[startIndex == 0 ? invocationCount - 1 : 0];

                        // General case
                        var newInvocationList = new Delegate[leftInvocationCount];

                        int j;
                        for (j = 0; j < startIndex; j++)
                            newInvocationList[j] = invocationList[j];
                        for (j += removedInvocationCount; j < invocationCount; j++)
                            newInvocationList[j - removedInvocationCount] = invocationList[j];

                        return NewMulticast(newInvocationList);
		            }
		        }
		    }

            // No changes
		    return this;
		}
Beispiel #17
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.
        protected virtual Delegate RemoveImpl(Delegate d)
        {
            // There is a special case were we are removing using a delegate as
            //    the value we need to check for this case
            //
            MulticastDelegate v = d as MulticastDelegate;

            if (v == null)
            {
                return(this);
            }
            if (v.m_helperObject as Delegate[] == null)
            {
                Delegate[] invocationList = m_helperObject as Delegate[];
                if (invocationList == null)
                {
                    // they are both not real Multicast
                    if (this.Equals(d))
                    {
                        return(null);
                    }
                }
                else
                {
                    int invocationCount = (int)m_extraFunctionPointerOrData;
                    for (int i = invocationCount; --i >= 0;)
                    {
                        if (d.Equals(invocationList[i]))
                        {
                            if (invocationCount == 2)
                            {
                                // Special case - only one value left, either at the beginning or the end
                                return(invocationList[1 - i]);
                            }
                            else
                            {
                                Delegate[] list = DeleteFromInvocationList(invocationList, invocationCount, i, 1);
                                return(NewMulticastDelegate(list, invocationCount - 1, true));
                            }
                        }
                    }
                }
            }
            else
            {
                Delegate[] invocationList = m_helperObject as Delegate[];
                if (invocationList != null)
                {
                    int invocationCount  = (int)m_extraFunctionPointerOrData;
                    int vInvocationCount = (int)v.m_extraFunctionPointerOrData;
                    for (int i = invocationCount - vInvocationCount; i >= 0; i--)
                    {
                        if (EqualInvocationLists(invocationList, v.m_helperObject as Delegate[], i, vInvocationCount))
                        {
                            if (invocationCount - vInvocationCount == 0)
                            {
                                // Special case - no values left
                                return(null);
                            }
                            else if (invocationCount - vInvocationCount == 1)
                            {
                                // Special case - only one value left, either at the beginning or the end
                                return(invocationList[i != 0 ? 0 : invocationCount - 1]);
                            }
                            else
                            {
                                Delegate[] list = DeleteFromInvocationList(invocationList, invocationCount, i, vInvocationCount);
                                return(NewMulticastDelegate(list, invocationCount - vInvocationCount, true));
                            }
                        }
                    }
                }
            }

            return(this);
        }
Beispiel #18
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.
        internal 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
            //
            MulticastDelegate v = value as MulticastDelegate;

            if (v == null)
                return this;
            if (v.m_helperObject as Delegate[] == null)
            {
                Delegate[] invocationList = m_helperObject as Delegate[];
                if (invocationList == null)
                {
                    // they are both not real Multicast
                    if (this.Equals(value))
                        return null;
                }
                else
                {
                    int invocationCount = (int)m_extraFunctionPointerOrData;
                    for (int i = invocationCount; --i >= 0;)
                    {
                        if (value.Equals(invocationList[i]))
                        {
                            if (invocationCount == 2)
                            {
                                // Special case - only one value left, either at the beginning or the end
                                return invocationList[1 - i];
                            }
                            else
                            {
                                Delegate[] list = DeleteFromInvocationList(invocationList, invocationCount, i, 1);
                                return NewMulticastDelegate(list, invocationCount - 1, true);
                            }
                        }
                    }
                }
            }
            else
            {
                Delegate[] invocationList = m_helperObject as Delegate[];
                if (invocationList != null)
                {
                    int invocationCount = (int)m_extraFunctionPointerOrData;
                    int vInvocationCount = (int)v.m_extraFunctionPointerOrData;
                    for (int i = invocationCount - vInvocationCount; i >= 0; i--)
                    {
                        if (EqualInvocationLists(invocationList, v.m_helperObject as Delegate[], i, vInvocationCount))
                        {
                            if (invocationCount - vInvocationCount == 0)
                            {
                                // Special case - no values left
                                return null;
                            }
                            else if (invocationCount - vInvocationCount == 1)
                            {
                                // Special case - only one value left, either at the beginning or the end
                                return invocationList[i != 0 ? 0 : invocationCount - 1];
                            }
                            else
                            {
                                Delegate[] list = DeleteFromInvocationList(invocationList, invocationCount, i, vInvocationCount);
                                return NewMulticastDelegate(list, invocationCount - vInvocationCount, true);
                            }
                        }
                    }
                }
            }

            return this;
        }
		protected virtual Delegate RemoveImpl(Delegate d)
		{
			if (!d.Equals(this))
			{
				return this;
			}
			return null;
		}
        protected override sealed Delegate RemoveImpl(Delegate value)
        {
            MulticastDelegate multicastDelegate = value as MulticastDelegate;

            if (multicastDelegate == null)
            {
                return((Delegate)this);
            }
            if (!(multicastDelegate._invocationList is object[]))
            {
                object[] invocationList = this._invocationList as object[];
                if (invocationList == null)
                {
                    if (this.Equals((object)value))
                    {
                        return((Delegate)null);
                    }
                }
                else
                {
                    int invocationCount = (int)this._invocationCount;
                    int deleteIndex     = invocationCount;
                    while (--deleteIndex >= 0)
                    {
                        if (value.Equals(invocationList[deleteIndex]))
                        {
                            if (invocationCount == 2)
                            {
                                return((Delegate)invocationList[1 - deleteIndex]);
                            }
                            return((Delegate)this.NewMulticastDelegate(this.DeleteFromInvocationList(invocationList, invocationCount, deleteIndex, 1), invocationCount - 1, true));
                        }
                    }
                }
            }
            else
            {
                object[] objArray = this._invocationList as object[];
                if (objArray != null)
                {
                    int invocationCount = (int)this._invocationCount;
                    int num             = (int)multicastDelegate._invocationCount;
                    for (int index = invocationCount - num; index >= 0; --index)
                    {
                        if (this.EqualInvocationLists(objArray, multicastDelegate._invocationList as object[], index, num))
                        {
                            if (invocationCount - num == 0)
                            {
                                return((Delegate)null);
                            }
                            if (invocationCount - num == 1)
                            {
                                return((Delegate)objArray[index != 0 ? 0 : invocationCount - 1]);
                            }
                            return((Delegate)this.NewMulticastDelegate(this.DeleteFromInvocationList(objArray, invocationCount, index, num), invocationCount - num, true));
                        }
                    }
                }
            }
            return((Delegate)this);
        }
Beispiel #21
0
        public override bool Equals(object obj)
        {
            ListenerSorter listenerSorter = (ListenerSorter)obj;

            return(deleg.Equals(listenerSorter.deleg));
        }
        protected sealed override Delegate RemoveImpl(Delegate removed)
        {
            if (removed == null)
            {
                return(this);
            }

            var removedMulticast = removed as MulticastDelegate;

            if (removedMulticast == null || removedMulticast.invocationList == null)
            {
                if (invocationList == null)
                {
                    // Both non multicast Delegate, so nothing left
                    if (base.Equals(removed))
                    {
                        return(null);
                    }
                }
                else
                {
                    // Remove from list
                    int invocationCount = invocationList.Length;
                    for (int i = invocationCount; --i >= 0;)
                    {
                        if (removed.Equals(invocationList[i]))
                        {
                            // Only two delegates?
                            // Returns the other one
                            if (invocationCount == 2)
                            {
                                return(invocationList[1 - i]);
                            }

                            var newInvocationList = new Delegate[invocationCount - 1];

                            int j;
                            for (j = 0; j < i; j++)
                            {
                                newInvocationList[j] = invocationList[j];
                            }
                            for (j++; j < invocationCount; j++)
                            {
                                newInvocationList[j - 1] = invocationList[j];
                            }

                            return(NewMulticast(newInvocationList));
                        }
                    }
                }
            }
            else
            {
                var removedInvocationList  = removedMulticast.invocationList;
                var removedInvocationCount = removedInvocationList.Length;

                // Removing a multicast delegate from a delegate wouldn't make sense, only consider the case
                // where we remove a multicast from a multicast
                if (invocationList != null)
                {
                    int invocationCount = invocationList.Length;

                    // Iterate over every possible range
                    // TODO: KPM?
                    for (int startIndex = invocationCount - removedInvocationCount; startIndex >= 0; --startIndex)
                    {
                        // Compare ranges
                        var equal = true;
                        for (int i = 0; i < removedInvocationCount; i++)
                        {
                            if (!(invocationList[startIndex + i].Equals(removedInvocationList[i])))
                            {
                                equal = false;
                                break;
                            }
                        }

                        if (!equal)
                        {
                            continue; // Try startIndex - 1
                        }
                        // We have a match
                        var leftInvocationCount = invocationCount - removedInvocationCount;

                        // Nothing left?
                        if (leftInvocationCount == 0)
                        {
                            return(null);
                        }

                        // Only one value left? (last or first)
                        if (leftInvocationCount == 1)
                        {
                            return(invocationList[startIndex == 0 ? invocationCount - 1 : 0]);
                        }

                        // General case
                        var newInvocationList = new Delegate[leftInvocationCount];

                        int j;
                        for (j = 0; j < startIndex; j++)
                        {
                            newInvocationList[j] = invocationList[j];
                        }
                        for (j += removedInvocationCount; j < invocationCount; j++)
                        {
                            newInvocationList[j - removedInvocationCount] = invocationList[j];
                        }

                        return(NewMulticast(newInvocationList));
                    }
                }
            }

            // No changes
            return(this);
        }
Beispiel #23
0
 protected virtual Delegate?RemoveImpl(Delegate d) => d.Equals(this) ? null : this;
        protected sealed override Delegate RemoveImpl(Delegate value)
        {
            MulticastDelegate multicastDelegate = value as MulticastDelegate;

            if (multicastDelegate == null)
            {
                return(this);
            }
            if (!(multicastDelegate._invocationList is object[]))
            {
                object[] array = this._invocationList as object[];
                if (array == null)
                {
                    if (this.Equals(value))
                    {
                        return(null);
                    }
                }
                else
                {
                    int num  = (int)this._invocationCount;
                    int num2 = num;
                    while (--num2 >= 0)
                    {
                        if (value.Equals(array[num2]))
                        {
                            if (num == 2)
                            {
                                return((Delegate)array[1 - num2]);
                            }
                            object[] invocationList = this.DeleteFromInvocationList(array, num, num2, 1);
                            return(this.NewMulticastDelegate(invocationList, num - 1, true));
                        }
                    }
                }
            }
            else
            {
                object[] array2 = this._invocationList as object[];
                if (array2 != null)
                {
                    int num3 = (int)this._invocationCount;
                    int num4 = (int)multicastDelegate._invocationCount;
                    int i    = num3 - num4;
                    while (i >= 0)
                    {
                        if (this.EqualInvocationLists(array2, multicastDelegate._invocationList as object[], i, num4))
                        {
                            if (num3 - num4 == 0)
                            {
                                return(null);
                            }
                            if (num3 - num4 == 1)
                            {
                                return((Delegate)array2[(i != 0) ? 0 : (num3 - 1)]);
                            }
                            object[] invocationList2 = this.DeleteFromInvocationList(array2, num3, i, num4);
                            return(this.NewMulticastDelegate(invocationList2, num3 - num4, true));
                        }
                        else
                        {
                            i--;
                        }
                    }
                }
            }
            return(this);
        }
Beispiel #25
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.
        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
            //
            MulticastDelegate v = value as MulticastDelegate;

            if (v == null)
            {
                return(this);
            }
            if (v._invocationList as Object[] == null)
            {
                Object[] invocationList = _invocationList as Object[];
                if (invocationList == null)
                {
                    // they are both not real Multicast
                    if (this.Equals(value))
                    {
                        return(null);
                    }
                }
                else
                {
                    int invocationCount = (int)_invocationCount;
                    for (int i = invocationCount; --i >= 0;)
                    {
                        if (value.Equals(invocationList[i]))
                        {
                            if (invocationCount == 2)
                            {
                                // Special case - only one value left, either at the beginning or the end
                                return((Delegate)invocationList[1 - i]);
                            }
                            else
                            {
                                Object[] list = DeleteFromInvocationList(invocationList, invocationCount, i, 1);
                                return(NewMulticastDelegate(list, invocationCount - 1, true));
                            }
                        }
                    }
                }
            }
            else
            {
                Object[] invocationList = _invocationList as Object[];
                if (invocationList != null)
                {
                    int invocationCount  = (int)_invocationCount;
                    int vInvocationCount = (int)v._invocationCount;
                    for (int i = invocationCount - vInvocationCount; i >= 0; i--)
                    {
                        if (EqualInvocationLists(invocationList, v._invocationList as Object[], i, vInvocationCount))
                        {
                            if (invocationCount - vInvocationCount == 0)
                            {
                                // Special case - no values left
                                return(null);
                            }
                            else if (invocationCount - vInvocationCount == 1)
                            {
                                // Special case - only one value left, either at the beginning or the end
                                return((Delegate)invocationList[i != 0 ? 0 : invocationCount - 1]);
                            }
                            else
                            {
                                Object[] list = DeleteFromInvocationList(invocationList, invocationCount, i, vInvocationCount);
                                return(NewMulticastDelegate(list, invocationCount - vInvocationCount, true));
                            }
                        }
                    }
                }
            }

            return(this);
        }
        protected sealed override Delegate RemoveImpl(Delegate value)
        {
            MulticastDelegate delegate2 = value as MulticastDelegate;

            if (delegate2 != null)
            {
                if (delegate2._invocationList is object[])
                {
                    object[] a = this._invocationList as object[];
                    if (a != null)
                    {
                        int invocationCount = (int)this._invocationCount;
                        int count           = (int)delegate2._invocationCount;
                        for (int i = invocationCount - count; i >= 0; i--)
                        {
                            if (this.EqualInvocationLists(a, delegate2._invocationList as object[], i, count))
                            {
                                if ((invocationCount - count) == 0)
                                {
                                    return(null);
                                }
                                if ((invocationCount - count) == 1)
                                {
                                    return((Delegate)a[(i != 0) ? 0 : (invocationCount - 1)]);
                                }
                                object[] invocationList = this.DeleteFromInvocationList(a, invocationCount, i, count);
                                return(this.NewMulticastDelegate(invocationList, invocationCount - count, true));
                            }
                        }
                    }
                }
                else
                {
                    object[] objArray = this._invocationList as object[];
                    if (objArray == null)
                    {
                        if (this.Equals(value))
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        int num   = (int)this._invocationCount;
                        int index = num;
                        while (--index >= 0)
                        {
                            if (value.Equals(objArray[index]))
                            {
                                if (num == 2)
                                {
                                    return((Delegate)objArray[1 - index]);
                                }
                                object[] objArray2 = this.DeleteFromInvocationList(objArray, num, index, 1);
                                return(this.NewMulticastDelegate(objArray2, num - 1, true));
                            }
                        }
                    }
                }
            }
            return(this);
        }
Beispiel #27
0
        protected override sealed Delegate RemoveImpl(Delegate value)
        {
            MulticastDelegate v = value as MulticastDelegate;

            if (v == null)
            {
                return(this);
            }
            if (v._invocationList == null)
            {
                MulticastDelegate[] invocationList = _invocationList;
                if (invocationList == null)
                {
                    if (this.Equals(value))
                    {
                        return(null);
                    }
                }
                else
                {
                    int invocationCount = (int)_invocationCount;
                    for (int i = invocationCount; --i >= 0;)
                    {
                        if (value.Equals(invocationList[i]))
                        {
                            if (invocationCount == 2)
                            {
                                // Special case - only one value left, either at the beginning or the end
                                return((Delegate)invocationList[1 - i]);
                            }
                            else
                            {
                                MulticastDelegate[] list = DeleteFromInvocationList(invocationList, invocationCount, i, 1);
                                return(NewMulticastDelegate(list, invocationCount - 1));
                            }
                        }
                    }
                }
            }
            else
            {
                MulticastDelegate[] invocationList = _invocationList;
                if (invocationList != null)
                {
                    int invocationCount  = (int)_invocationCount;
                    int vInvocationCount = (int)v._invocationCount;
                    for (int i = invocationCount - vInvocationCount; i >= 0; i--)
                    {
                        if (EqualInvocationLists(invocationList, v._invocationList, i, vInvocationCount))
                        {
                            if (invocationCount - vInvocationCount == 0)
                            {
                                return(null);
                            }
                            else if (invocationCount - vInvocationCount == 1)
                            {
                                return((Delegate)invocationList[i != 0 ? 0 : invocationCount - 1]);
                            }
                            else
                            {
                                MulticastDelegate[] list = DeleteFromInvocationList(invocationList, invocationCount, i, vInvocationCount);
                                return(NewMulticastDelegate(list, invocationCount - vInvocationCount));
                            }
                        }
                    }
                }
            }

            return(this);
        }
 protected virtual Delegate RemoveImpl(Delegate d)
 {
     return (d.Equals(this)) ? null : this;
 }
		protected sealed override Delegate RemoveImpl(Delegate value)
		{
			MulticastDelegate multicastDelegate = value as MulticastDelegate;
			if (multicastDelegate == null)
			{
				return this;
			}
			if (!(multicastDelegate._invocationList is object[]))
			{
				object[] array = this._invocationList as object[];
				if (array == null)
				{
					if (this.Equals(value))
					{
						return null;
					}
				}
				else
				{
					int num = (int)this._invocationCount;
					int num2 = num;
					while (--num2 >= 0)
					{
						if (value.Equals(array[num2]))
						{
							if (num == 2)
							{
								return (Delegate)array[1 - num2];
							}
							object[] invocationList = this.DeleteFromInvocationList(array, num, num2, 1);
							return this.NewMulticastDelegate(invocationList, num - 1, true);
						}
					}
				}
			}
			else
			{
				object[] array2 = this._invocationList as object[];
				if (array2 != null)
				{
					int num3 = (int)this._invocationCount;
					int num4 = (int)multicastDelegate._invocationCount;
					int i = num3 - num4;
					while (i >= 0)
					{
						if (this.EqualInvocationLists(array2, multicastDelegate._invocationList as object[], i, num4))
						{
							if (num3 - num4 == 0)
							{
								return null;
							}
							if (num3 - num4 == 1)
							{
								return (Delegate)array2[(i != 0) ? 0 : (num3 - 1)];
							}
							object[] invocationList2 = this.DeleteFromInvocationList(array2, num3, i, num4);
							return this.NewMulticastDelegate(invocationList2, num3 - num4, true);
						}
						else
						{
							i--;
						}
					}
				}
			}
			return this;
		}