Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ coverage.xml
*.vcxproj.filters
*.userprefs
*.DotSettings.user
.runsettings

# Build results
[Bb]in/
Expand Down
12 changes: 10 additions & 2 deletions src/runtime/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ private static Func<object, bool> GetIsTransparentProxy()

internal static NewReference ToPythonDetectType(object? value)
=> value is null ? new NewReference(Runtime.PyNone) : ToPython(value, value.GetType());
internal static NewReference ToPython(object? value, Type type)


internal static NewReference ToPython(object? value, Type type, bool wrapInterface = false)
{
if (value is PyObject pyObj)
{
Expand All @@ -144,6 +146,12 @@ internal static NewReference ToPython(object? value, Type type)
return CLRObject.GetReference(value, type);
}

if (wrapInterface && type.IsInterface)
{
var ifaceObj = (InterfaceObject)ClassManager.GetClassImpl(type);
return ifaceObj.TryWrapObject(value);
}

// it the type is a python subclass of a managed type then return the
// underlying python object rather than construct a new wrapper object.
if (value is IPythonDerivedType pyderived)
Expand Down Expand Up @@ -979,7 +987,7 @@ public static PyObject ToPython(this object? o)
public static PyObject ToPythonAs<T>(this T? o)
{
if (o is null) return Runtime.None;
return Converter.ToPython(o, typeof(T)).MoveToPyObject();
return Converter.ToPython(o, typeof(T), true).MoveToPyObject();
}
}
}
Loading