X Tutup
Skip to content

Commit 9135b94

Browse files
authored
match python type T to Nullable<T> in C#
When a method parameter in C# is defined as Nullable like `int?` and you call it in python by a literal int number, it does not match with `int?` and could not bind the method. At least in .NETStandard2.0. So this update is telling the MethodBinder class that a primitive value (with the type of T) in python can be matched with the corresponding primitive type (T) in C# or Nullable<T> too.
1 parent 7a9dcfa commit 9135b94

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/runtime/methodbinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static Type TryComputeClrArgumentType(Type parameterType, IntPtr argument, bool
523523
if (clrtype != null)
524524
{
525525
var typematch = false;
526-
if ((parameterType != typeof(object)) && (parameterType != clrtype))
526+
if (parameterType != typeof(object) && parameterType != clrtype && Nullable.GetUnderlyingType(parameterType) != clrtype)
527527
{
528528
IntPtr pytype = Converter.GetPythonTypeByAlias(parameterType);
529529
pyoptype = Runtime.PyObject_Type(argument);

0 commit comments

Comments
 (0)
X Tutup