◐ Shell
clean mode source ↗

Added `ToPythonAs<T>()` by lostmsu · Pull Request #2330 · pythonnet/pythonnet

Expand Up @@ -133,7 +133,8 @@ internal static NewReference ToPython(object? value, Type type) if (EncodableByUser(type, value)) { var encoded = PyObjectConversions.TryEncode(value, type); if (encoded != null) { if (encoded != null) { return new NewReference(encoded); } } Expand Down Expand Up @@ -334,7 +335,7 @@ internal static bool ToManagedValue(BorrowedReference value, Type obType,
if (obType.IsGenericType && obType.GetGenericTypeDefinition() == typeof(Nullable<>)) { if( value == Runtime.PyNone ) if (value == Runtime.PyNone) { result = null; return true; Expand Down Expand Up @@ -980,5 +981,11 @@ public static PyObject ToPython(this object? o) if (o is null) return Runtime.None; return Converter.ToPython(o, o.GetType()).MoveToPyObject(); }
public static PyObject ToPythonAs<T>(this T? o)
Comment thread

filmor marked this conversation as resolved.

{ if (o is null) return Runtime.None; return Converter.ToPython(o, typeof(T)).MoveToPyObject(); } } }