public override bool Equals(object obj) { if ((obj == null) || !InternalEqualTypes(this, obj)) { return(false); } Delegate delegate2 = (Delegate)obj; if (((this._target == delegate2._target) && (this._methodPtr == delegate2._methodPtr)) && (this._methodPtrAux == delegate2._methodPtrAux)) { return(true); } if (this._methodPtrAux.IsNull()) { if (!delegate2._methodPtrAux.IsNull()) { return(false); } if (this._target != delegate2._target) { return(false); } } else { if (delegate2._methodPtrAux.IsNull()) { return(false); } if (this._methodPtrAux == delegate2._methodPtrAux) { return(true); } } if ((this._methodBase != null) && (delegate2._methodBase != null)) { return(this._methodBase.Equals(delegate2._methodBase)); } return(this.FindMethodHandle().Equals(delegate2.FindMethodHandle())); }
public override bool Equals(Object obj) { if (obj == null || !InternalEqualTypes(this, obj)) { return(false); } Delegate d = (Delegate)obj; // do an optimistic check first. This is hopefully cheap enough to be worth if (_target == d._target && _methodPtr == d._methodPtr && _methodPtrAux == d._methodPtrAux) { return(true); } // even though the fields were not all equals the delegates may still match // When target carries the delegate itself the 2 targets (delegates) may be different instances // but the delegates are logically the same // It may also happen that the method pointer was not jitted when creating one delegate and jitted in the other // if that's the case the delegates may still be equals but we need to make a more complicated check if (_methodPtrAux.IsNull()) { if (!d._methodPtrAux.IsNull()) { return(false); // different delegate kind } // they are both closed over the first arg if (_target != d._target) { return(false); } // fall through method handle check } else { if (d._methodPtrAux.IsNull()) { return(false); // different delegate kind } // Ignore the target as it will be the delegate instance, though it may be a different one /* * if (_methodPtr != d._methodPtr) * return false; */ if (_methodPtrAux == d._methodPtrAux) { return(true); } // fall through method handle check } // method ptrs don't match, go down long path // if (_methodBase == null || d._methodBase == null) { return(FindMethodHandle().Equals(d.FindMethodHandle())); } else { return(_methodBase.Equals(d._methodBase)); } }