From 9135b9443dcd7c9c90b5d2ffaa02730959e01801 Mon Sep 17 00:00:00 2001 From: Majid Hatami Date: Thu, 30 Jul 2020 06:53:29 +0430 Subject: [PATCH] match python type T to Nullable 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 too. --- src/runtime/methodbinder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index b3186a3f2..b26b5d2fc 100644 --- a/src/runtime/methodbinder.cs +++ b/src/runtime/methodbinder.cs @@ -523,7 +523,7 @@ static Type TryComputeClrArgumentType(Type parameterType, IntPtr argument, bool if (clrtype != null) { var typematch = false; - if ((parameterType != typeof(object)) && (parameterType != clrtype)) + if (parameterType != typeof(object) && parameterType != clrtype && Nullable.GetUnderlyingType(parameterType) != clrtype) { IntPtr pytype = Converter.GetPythonTypeByAlias(parameterType); pyoptype = Runtime.PyObject_Type(argument);