Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Allow passing None for nullable args#460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
filmor merged 1 commit intopythonnet:masterfromdhirschfeld:null-args
May 10, 2017
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionssrc/runtime/converter.cs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssrc/testing/conversiontest.cs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssrc/tests/test_conversion.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp