Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 11 src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,17 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
return true;
}

if (obType.IsGenericType && obType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
if( value == Runtime.PyNone )
{
result = null;
return true;
}
// Set type to underlying type
obType = obType.GetGenericArguments()[0];
}

if (obType.IsArray)
{
return ToArray(value, obType, out result, setError);
Expand Down
6 changes: 6 additions & 0 deletions 6 src/testing/conversiontest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ public ConversionTest()

public byte[] ByteArrayField;
public sbyte[] SByteArrayField;

public T? Echo<T>(T? arg) where T: struct {
return arg;
}

}



public interface ISpam
{
Expand Down
6 changes: 6 additions & 0 deletions 6 src/tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,8 @@ def test_enum_conversion():

def test_null_conversion():
"""Test null conversion."""
import System

ob = ConversionTest()

ob.StringField = None
Expand All @@ -652,6 +654,10 @@ def test_null_conversion():
ob.SpamField = None
assert ob.SpamField is None

pi = 22/7
assert ob.Echo[System.Double](pi) == pi
assert ob.Echo[System.DateTime](None) is None

# Primitive types and enums should not be set to null.

with pytest.raises(TypeError):
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.