Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,6 @@ public sealed override unsafe bool Equals([NotNullWhen(true)] object? obj)
// unmanaged
if (IsUnmanagedFunctionPtr)
return other.IsUnmanagedFunctionPtr && _methodPtrAux == other._methodPtrAux;

// Under cached interface dispatch we might see the shared CID_VirtualOpenDelegateDispatch stub.
// Fallback to desc comparison in such case for correctness.
#if !FEATURE_CACHED_INTERFACE_DISPATCH
// both delegates are open
if (_methodPtrAux == other._methodPtrAux)
return true;
#endif
}

// It's possible that the method pointer was JITted in one delegate but not the other.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,15 @@ private static void IntIntMethod(int expected, int actual)
Assert.Equal(expected, actual);
}

[Fact]
public static void DifferentMethodForDerivedBase()
{
var d1 = (Action<Derived>)Delegate.CreateDelegate(typeof(Action<Derived>), typeof(Base).GetMethod("M")!);
var d2 = (Action<Derived>)Delegate.CreateDelegate(typeof(Action<Derived>), typeof(Derived).GetMethod("M")!);
Assert.False(d1.Equals(d2));
Assert.False(d1.Method.Equals(d2.Method));
}

[Fact]
public static void SameMethodObtainedViaDelegateAndReflectionAreSameForClass()
{
Expand Down Expand Up @@ -571,6 +580,9 @@ internal virtual void M1() { }
internal virtual void M2() { }
}

class Base { public virtual void M() { } }
class Derived : Base { public override void M() { } }

private delegate void IntIntDelegate(int expected, int actual);
private delegate void IntIntDelegateWithDefault(int expected, int actual = 7);

Expand Down
Loading