Skip to content
Merged
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
10 changes: 10 additions & 0 deletions src/libraries/System.Runtime/tests/System/DelegateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ public static void CreateDelegate2()
e = (E)Delegate.CreateDelegate(typeof(E), new C(), "DoExecute");
Assert.NotNull(e);
Assert.Equal(102, e(new C()));

e = (E)Delegate.CreateDelegate(typeof(E), new B() { field = 42 }, "GetField");
Assert.NotNull(e);
Assert.Equal(42, e(new C()));
}

[Fact]
Expand Down Expand Up @@ -1103,6 +1107,7 @@ public static void CreateDelegate9_Type_Null()

public class B
{
public int field;

public virtual string retarg3(string s)
{
Expand Down Expand Up @@ -1136,6 +1141,11 @@ public int StartExecute(C c, B b)
{
return 3;
}

public int GetField(C c)
{
return field;
}
}

public class C : B, Iface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static Delegate CreateDelegate(Type type, object? firstArgument, MethodIn
return null;
}

return CreateDelegate_internal(type, null, info, throwOnBindFailure);
return CreateDelegate_internal(type, target, info, throwOnBindFailure);
}

[RequiresUnreferencedCode("The target method might be removed")]
Expand Down