NumberToUInt32() private static method

private static NumberToUInt32 ( NumberBuffer &number, UInt32 &value ) : Boolean
number NumberBuffer
value UInt32
return Boolean
Beispiel #1
0
        internal static unsafe uint ParseUInt32(string value, NumberStyles options, NumberFormatInfo numfmt)
        {
            byte *stackBuffer = stackalloc byte[Number.NumberBuffer.NumberBufferBytes];

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

            Number.StringToNumber(value, options, ref number, numfmt, false);
            if ((options & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if (!Number.HexNumberToUInt32(ref number, ref num))
                {
                    throw new OverflowException(Environment.GetResourceString("Overflow_UInt32"));
                }
            }
            else if (!Number.NumberToUInt32(ref number, ref num))
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_UInt32"));
            }
            return(num);
        }
Beispiel #2
0
        internal static unsafe bool TryParseUInt32(string s, NumberStyles style, NumberFormatInfo info, out uint result)
        {
            byte *stackBuffer = stackalloc byte[Number.NumberBuffer.NumberBufferBytes];

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