NumberToInt32() private static method

private static NumberToInt32 ( NumberBuffer &number, Int32 &value ) : Boolean
number NumberBuffer
value Int32
return Boolean
Exemplo n.º 1
0
        internal static unsafe int ParseInt32(string s, NumberStyles style, NumberFormatInfo info)
        {
            byte *stackBuffer = stackalloc byte[Number.NumberBuffer.NumberBufferBytes];

            Number.NumberBuffer number = new Number.NumberBuffer(stackBuffer);
            int num = 0;

            Number.StringToNumber(s, style, ref number, info, false);
            if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if (!Number.HexNumberToInt32(ref number, ref num))
                {
                    throw new OverflowException(Environment.GetResourceString("Overflow_Int32"));
                }
            }
            else if (!Number.NumberToInt32(ref number, ref num))
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Int32"));
            }
            return(num);
        }
Exemplo n.º 2
0
        internal static unsafe bool TryParseInt32(string s, NumberStyles style, NumberFormatInfo info, out int result)
        {
            byte *stackBuffer = stackalloc byte[Number.NumberBuffer.NumberBufferBytes];

            Number.NumberBuffer number = new Number.NumberBuffer(stackBuffer);
            result = 0;
            if (!Number.TryStringToNumber(s, style, ref number, info, false))
            {
                return(false);
            }
            if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if (!Number.HexNumberToInt32(ref number, ref result))
                {
                    return(false);
                }
            }
            else if (!Number.NumberToInt32(ref number, ref result))
            {
                return(false);
            }
            return(true);
        }