public void TestAsLongGood()
        {
            var i = new PyLong(5);
            var a = PyLong.AsLong(i);

            Assert.AreEqual(5, a.ToInt32());
        }
示例#2
0
        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);
        }
示例#3
0
        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);
            }
        }