private PyObject_Repr ( IntPtr pointer ) : IntPtr | ||
pointer | IntPtr | |
return | IntPtr |
/// <summary> /// Repr Method /// </summary> /// <remarks> /// Return a string representation of the object. This method is /// the managed equivalent of the Python expression "repr(object)". /// </remarks> public string Repr() { IntPtr strval = Runtime.PyObject_Repr(obj); string result = Runtime.GetManagedString(strval); Runtime.XDecref(strval); return(result); }
private static void SetConversionError(IntPtr value, Type target) { IntPtr ob = Runtime.PyObject_Repr(value); string src = Runtime.GetManagedString(ob); Runtime.XDecref(ob); Exceptions.SetError(Exceptions.TypeError, $"Cannot convert {src} to {target}"); }
static void SetConversionError(IntPtr value, Type target) { IntPtr ob = Runtime.PyObject_Repr(value); string src = Runtime.GetManagedString(ob); Runtime.Decref(ob); string error = String.Format( "Cannot convert {0} to {1}", src, target ); Exceptions.SetError(Exceptions.TypeError, error); }
private static void SetConversionError(IntPtr value, Type target) { // PyObject_Repr might clear the error Runtime.PyErr_Fetch(out var causeType, out var causeVal, out var causeTrace); IntPtr ob = Runtime.PyObject_Repr(value); string src = Runtime.GetManagedString(ob); Runtime.XDecref(ob); Runtime.PyErr_Restore(causeType.StealNullable(), causeVal.StealNullable(), causeTrace.StealNullable()); Exceptions.RaiseTypeError($"Cannot convert {src} to {target}"); }
public static void Print(string msg, BorrowedReference member) { string result = msg; result += " "; if (member == null) { Console.WriteLine("null arg to print"); } using var ob = Runtime.PyObject_Repr(member); result += Runtime.GetManagedString(ob.BorrowOrThrow()); result += " "; Console.WriteLine(result); }
public static void Print(string msg, params IntPtr[] args) { string result = msg; result += " "; foreach (IntPtr t in args) { if (t == IntPtr.Zero) { Console.WriteLine("null arg to print"); } IntPtr ob = Runtime.PyObject_Repr(t); result += Runtime.GetManagedString(ob); Runtime.XDecref(ob); result += " "; } Console.WriteLine(result); }
public static void Print(string msg, params IntPtr[] args) { string result = msg; result += " "; for (int i = 0; i < args.Length; i++) { if (args[i] == IntPtr.Zero) { Console.WriteLine("null arg to print"); } IntPtr ob = Runtime.PyObject_Repr(args[i]); result += Runtime.GetManagedString(ob); Runtime.Decref(ob); result += " "; } Console.WriteLine(result); return; }
private static void SetConversionError(BorrowedReference value, Type target) { // PyObject_Repr might clear the error Runtime.PyErr_Fetch(out var causeType, out var causeVal, out var causeTrace); var ob = Runtime.PyObject_Repr(value); string src = "'object has no repr'"; if (ob.IsNull()) { Exceptions.Clear(); } else { src = Runtime.GetManagedString(ob.Borrow()) ?? src; } ob.Dispose(); Runtime.PyErr_Restore(causeType.StealNullable(), causeVal.StealNullable(), causeTrace.StealNullable()); Exceptions.RaiseTypeError($"Cannot convert {src} to {target}"); }