public void TestAsLongGood() { var i = new PyLong(5); var a = PyLong.AsLong(i); Assert.AreEqual(5, a.ToInt32()); }
public void TestAsLongBad() { var s = new PyString("Foo"); PyLong a = null; var ex = Assert.Throws<PythonException>(() => a = PyLong.AsLong(s)); StringAssert.StartsWith("invalid literal", ex.Message); Assert.IsNull(a); }
public bool TryDecode <T>(PyObject pyObj, out T value) { if (!PyLong.IsLongType(pyObj)) { value = default; return(false); } using (var pyLong = PyLong.AsLong(pyObj)) { value = (T)(object)pyLong.ToBigInteger(); return(true); } }