Skip to content
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
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
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ Ansys fork of `pythonnet <https://github.com/pythonnet/pythonnet>`_.
We will try to keep this up-to-date with pythonnet and upstream changes that might benefit the pythonnet community

Changes relative to pythonnet:
- Revert of `#1240 <https://github.com/pythonnet/pythonnet/pull/1240>`_.
- Enum REPR `#2239 <https://github.com/pythonnet/pythonnet/pull/2239>` is included in this release of version 3.0.2, but is unreleased in pythonnet

* Revert of `#1240 <https://github.com/pythonnet/pythonnet/pull/1240>`_.
* Enum REPR `#2239 <https://github.com/pythonnet/pythonnet/pull/2239>` is included in this release of version 3.0.2, but is unreleased in pythonnet
* Opt-into explicit interface wrapping, `#19 <https://github.com/ansys/ansys-pythonnet/pull/19>`. This opts into the behavior that became the default in #1240 if ToPythonAs<T> is explicitly used
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