public static IntPtr ToPython(object value) { if (value == null) { return(Py_None); } PythonObject result = PythonObject.From(value); if (result != null) { return(result); } if (ClrToPython.ContainsKey(value)) { return((PythonObject)ClrToPython[value]); } Type type = value.GetType(); PythonClass pythonType = TypeManager.ToPython(type); result = pythonType.CreateEmpty(); Register(value, result); return(result); }
public static IntPtr ConstructorProxy(object instance, IntPtr type, object[] args) { int length = args?.Length ?? 0; PythonTuple tuple = new PythonTuple(length); for (int i = 0; i < length; i++) { tuple[i] = PythonObject.From(args[i]); } PythonObject result; using (PythonException.Checker) result = PyObject_CallObject(type, tuple); ObjectManager.Register(instance, result); return(result); }
//[DebuggerHidden] public static object MethodProxy(IntPtr instance, IntPtr method, object[] args) { int length = args?.Length ?? 0; PythonTuple parameters = new PythonTuple(length + 1); parameters[0] = instance; for (int i = 0; i < length; i++) { parameters[i + 1] = PythonObject.From(args[i]); } PythonObject result; using (PythonException.Checker) result = PyObject_CallObject(method, parameters); return(ObjectManager.FromPython(result)); // TODO: Send a type hint ? }