Example #1
0
        public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out SByte result)
        {
            UInt32.ValidateParseStyleInteger(style);
            result = 0;
            int i;

            if (!FormatProvider.TryParseInt32(s, style, provider, out i))
            {
                return(false);
            }

            if ((style & NumberStyles.AllowHexSpecifier) != 0)
            { // We are parsing a hexadecimal number
                if ((i < 0) || i > Byte.MaxValue)
                {
                    return(false);
                }
                result = (sbyte)i;
                return(true);
            }

            if (i < MinValue || i > MaxValue)
            {
                return(false);
            }
            result = (sbyte)i;
            return(true);
        }
Example #2
0
        public static sbyte Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            UInt32.ValidateParseStyleInteger(style);
            int i = 0;

            try
            {
                i = FormatProvider.ParseInt32(s, style, provider);
            }
            catch (OverflowException e)
            {
                throw new OverflowException(SR.Overflow_SByte, e);
            }

            if ((style & NumberStyles.AllowHexSpecifier) != 0)
            { // We are parsing a hexadecimal number
                if ((i < 0) || i > Byte.MaxValue)
                {
                    throw new OverflowException(SR.Overflow_SByte);
                }
                return((sbyte)i);
            }

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(SR.Overflow_SByte);
            }
            return((sbyte)i);
        }
Example #3
0
        public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Int16 result)
        {
            UInt32.ValidateParseStyleInteger(style);
            result = 0;
            int i;

            if (!FormatProvider.TryParseInt32(s, style, provider, out i))
            {
                return(false);
            }

            // We need this check here since we don't allow signs to specified in hex numbers. So we fixup the result
            // for negative numbers
            if ((style & NumberStyles.AllowHexSpecifier) != 0)
            { // We are parsing a hexadecimal number
                if ((i < 0) || i > UInt16.MaxValue)
                {
                    return(false);
                }
                result = (Int16)i;
                return(true);
            }

            if (i < MinValue || i > MaxValue)
            {
                return(false);
            }
            result = (Int16)i;
            return(true);
        }
Example #4
0
        public static short Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            UInt32.ValidateParseStyleInteger(style);
            int i = 0;

            try
            {
                i = FormatProvider.ParseInt32(s, style, provider);
            }
            catch (OverflowException e)
            {
                throw new OverflowException(SR.Overflow_Int16, e);
            }

            // We need this check here since we don't allow signs to specified in hex numbers. So we fixup the result
            // for negative numbers
            if ((style & NumberStyles.AllowHexSpecifier) != 0)
            { // We are parsing a hexadecimal number
                if ((i < 0) || (i > UInt16.MaxValue))
                {
                    throw new OverflowException(SR.Overflow_Int16);
                }
                return((short)i);
            }

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(SR.Overflow_Int16);
            }
            return((short)i);
        }
Example #5
0
        public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out UInt16 result)
        {
            UInt32.ValidateParseStyleInteger(style);
            result = 0;
            UInt32 i;

            if (!FormatProvider.TryParseUInt32(s, style, provider, out i))
            {
                return(false);
            }
            if (i > MaxValue)
            {
                return(false);
            }
            result = (UInt16)i;
            return(true);
        }
Example #6
0
        public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Byte result)
        {
            UInt32.ValidateParseStyleInteger(style);

            result = 0;
            int i;

            if (!FormatProvider.TryParseInt32(s, style, provider, out i))
            {
                return(false);
            }
            if (i < MinValue || i > MaxValue)
            {
                return(false);
            }
            result = (byte)i;
            return(true);
        }
Example #7
0
        public static ushort Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            UInt32.ValidateParseStyleInteger(style);
            uint i = 0;

            try
            {
                i = FormatProvider.ParseUInt32(s, style, provider);
            }
            catch (OverflowException e)
            {
                throw new OverflowException(SR.Overflow_UInt16, e);
            }

            if (i > MaxValue)
            {
                throw new OverflowException(SR.Overflow_UInt16);
            }
            return((ushort)i);
        }
Example #8
0
        public static byte Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            UInt32.ValidateParseStyleInteger(style);

            int i = 0;

            try
            {
                i = FormatProvider.ParseInt32(s, style, provider);
            }
            catch (OverflowException e)
            {
                throw new OverflowException(SR.Overflow_Byte, e);
            }

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(SR.Overflow_Byte);
            }
            return((byte)i);
        }
Example #9
0
 public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Int32 result)
 {
     UInt32.ValidateParseStyleInteger(style);
     return(FormatProvider.TryParseInt32(s, style, provider, out result));
 }
Example #10
0
 public static int Parse(String s, NumberStyles style, IFormatProvider provider)
 {
     UInt32.ValidateParseStyleInteger(style);
     return(FormatProvider.ParseInt32(s, style, provider));
 }
Example #11
0
 public static ushort Parse(String s, NumberStyles style)
 {
     UInt32.ValidateParseStyleInteger(style);
     return(Parse(s, style, null));
 }
Example #12
0
 public static ulong Parse(String s, NumberStyles style)
 {
     UInt32.ValidateParseStyleInteger(style);
     return(FormatProvider.ParseUInt64(s, style, null));
 }