Skip to content

Commit

Permalink
[mono] Pass delegate target when using CreateDelegate (#40321)
Browse files Browse the repository at this point in the history
* Pass delegate target when using CreateDelegate

* [tests] Add test that checks `this` with CreateDelegate API
  • Loading branch information
BrzVlad authored Aug 5, 2020
1 parent 69b91f9 commit fe41d3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit fe41d3c

Please sign in to comment.