if (flags & DBF_InstanceMethodOnly && pTargetMethod->IsStatic())
return false;
- // we don't allow you to bind to methods on Nullable<T> because the unboxing stubs don't know how to
- // handle this case.
- if (!pTargetMethod->IsStatic() && Nullable::IsNullableType(pTargetMethod->GetMethodTable()))
- return false;
-
// Get signatures for the delegate invoke and target methods.
MetaSig sigInvoke(pInvokeMethod, thDelegate);
MetaSig sigTarget(pTargetMethod, thExactMethodType);
Assert.Null(ex.InnerException);
Assert.NotNull(ex.Message);
}
+
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/49839", TestRuntimes.Mono)]
+ [Fact]
+ public static void CreateDelegate10_Nullable_Method()
+ {
+ int? num = 123;
+ MethodInfo mi = typeof(int?).GetMethod("ToString");
+ NullableIntToString toString = (NullableIntToString)Delegate.CreateDelegate(
+ typeof(NullableIntToString), mi);
+ string s = toString(ref num);
+ Assert.Equal(num.ToString(), s);
+ }
+
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/49839", TestRuntimes.Mono)]
+ [Fact]
+ public static void CreateDelegate10_Nullable_ClosedDelegate()
+ {
+ int? num = 123;
+ MethodInfo mi = typeof(int?).GetMethod("ToString");
+ AssertExtensions.Throws<ArgumentException>(
+ () => Delegate.CreateDelegate(typeof(NullableIntToString), num, mi));
+ }
#endregion Tests
#region Test Setup
public delegate void D(C c);
public delegate int E(C c);
+
+ delegate string NullableIntToString(ref int? obj);
#endregion Test Setup
}
}