Skip to content

Commit d0cd40f

Browse files
committed
Implements Nullable support
1 parent f7cc869 commit d0cd40f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/runtime/converter.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,12 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
507507
return false;
508508
}
509509

510+
var underlyingType = Nullable.GetUnderlyingType(obType);
511+
if (underlyingType != null)
512+
{
513+
return ToManagedValue(value, underlyingType, out result, setError);
514+
}
515+
510516
return ToPrimitive(value, obType, out result, setError);
511517
}
512518

@@ -966,7 +972,7 @@ private static bool ToArray(IntPtr value, Type obType, out object result, bool s
966972
int size = Runtime.PySequence_Size(value);
967973
result = null;
968974

969-
if (size < 0)
975+
if (size < 0 || elementType.IsGenericType)
970976
{
971977
if (setError)
972978
{

src/runtime/methodbinder.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,14 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
394394
}
395395
if (!typematch)
396396
{
397+
// this takes care of nullables
398+
var underlyingType = Nullable.GetUnderlyingType(pi[n].ParameterType);
399+
if (underlyingType == null)
400+
{
401+
underlyingType = pi[n].ParameterType;
402+
}
397403
// this takes care of enum values
398-
TypeCode argtypecode = Type.GetTypeCode(pi[n].ParameterType);
404+
TypeCode argtypecode = Type.GetTypeCode(underlyingType);
399405
TypeCode paramtypecode = Type.GetTypeCode(clrtype);
400406
if (argtypecode == paramtypecode)
401407
{

0 commit comments

Comments
 (0)