public static BigInteger GetBigInteger(dynamic dynLongPyObj, ref BigInteger?bigInt) { if (bigInt != null) { return((BigInteger)bigInt); } using (Py.GIL()) { var pyLong = new PyLong(dynLongPyObj); // This is inefficient, and should be reworked in the future var str = pyLong.ToString(); bigInt = BigInteger.Parse(str); return((BigInteger)bigInt); } }
public object this[object key] { get { var keyStr = key as string; if (keyStr != null) { if (_dictStrToNumber.ContainsKey(keyStr)) { return(_dictStrToNumber[keyStr]); } BigInteger valHash; using (Py.GIL()) { var dynPyNumber = _pyStringStore.__getitem__(key); var pyNumber = new PyLong(dynPyNumber); valHash = BigInteger.Parse(pyNumber.ToString()); _dictStrToNumber.Add(keyStr, valHash); } return(valHash); } var keyHash = key.AsBigInteger(); if (_dictNumberToStr.ContainsKey(keyHash)) { return(_dictNumberToStr[keyHash]); } var valStr = string.Empty; using (Py.GIL()) { var dynPyStr = _pyStringStore.__getitem__(key); var pyString = new PyString(dynPyStr); valStr = pyString.ToString(); _dictNumberToStr.Add(keyHash, valStr); } return(valStr); } }