ParseInt32() static private méthode

static private ParseInt32 ( String s, NumberStyles style, NumberFormatInfo info ) : Int32
s String
style NumberStyles
info NumberFormatInfo
Résultat Int32
Exemple #1
0
        private static short Parse(String s, NumberStyles style, NumberFormatInfo info)
        {
            int i = 0;

            try {
                i = Number.ParseInt32(s, style, info);
            }
            catch (OverflowException e) {
                throw new OverflowException(Environment.GetResourceString("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(Environment.GetResourceString("Overflow_Int16"));
                }
                return((short)i);
            }

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
            }
            return((short)i);
        }
Exemple #2
0
        private static sbyte Parse(ReadOnlySpan <char> s, NumberStyles style, NumberFormatInfo info)
        {
            int i = 0;

            try
            {
                i = Number.ParseInt32(s, style, info);
            }
            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);
        }
Exemple #3
0
        private static short Parse(ReadOnlySpan <char> s, NumberStyles style, NumberFormatInfo info)
        {
            int i = 0;

            try
            {
                i = Number.ParseInt32(s, style, info);
            }
            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);
        }
Exemple #4
0
        // Parses an integer from a String in the given style.  If
        // a NumberFormatInfo isn't specified, the current culture's
        // NumberFormatInfo is assumed.
        //
        /// <include file='doc\Int32.uex' path='docs/doc[@for="Int32.Parse3"]/*' />
        public static int Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);

            NumberFormatInfo.ValidateParseStyle(style);
            return(Number.ParseInt32(s, style, info));
        }
Exemple #5
0
        private static short Parse(string s, NumberStyles style, NumberFormatInfo info)
        {
            int int32;

            try
            {
                int32 = Number.ParseInt32(s, style, info);
            }
            catch (OverflowException ex)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Int16"), (Exception)ex);
            }
            if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if (int32 < 0 || int32 > (int)ushort.MaxValue)
                {
                    throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
                }
                return((short)int32);
            }
            if (int32 < (int)short.MinValue || int32 > (int)short.MaxValue)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
            }
            return((short)int32);
        }
Exemple #6
0
        // Token: 0x060012F6 RID: 4854 RVA: 0x00038078 File Offset: 0x00036278
        private static sbyte Parse(string s, NumberStyles style, NumberFormatInfo info)
        {
            int num = 0;

            try
            {
                num = Number.ParseInt32(s, style, info);
            }
            catch (OverflowException innerException)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_SByte"), innerException);
            }
            if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if (num < 0 || num > 255)
                {
                    throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
                }
                return((sbyte)num);
            }
            else
            {
                if (num < -128 || num > 127)
                {
                    throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
                }
                return((sbyte)num);
            }
        }
Exemple #7
0
        private static short Parse(string s, NumberStyles style, NumberFormatInfo info)
        {
            int num = 0;

            try
            {
                num = Number.ParseInt32(s, style, info);
            }
            catch (OverflowException exception)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Int16"), exception);
            }
            if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if ((num < 0) || (num > 0xffff))
                {
                    throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
                }
                return((short)num);
            }
            if ((num < -32768) || (num > 0x7fff))
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
            }
            return((short)num);
        }
Exemple #8
0
        private static sbyte Parse(String s, NumberStyles style, NumberFormatInfo info)
        {
            int i = 0;

            try
            {
                i = Number.ParseInt32(s, style, info);
            }
            catch (OverflowException e)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_SByte"), e);
            }

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

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
            }
            return((sbyte)i);
        }
Exemple #9
0
 public static int Parse(string s)
 {
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo));
 }
Exemple #10
0
 // Parses an integer from a String in the given style.  If
 // a NumberFormatInfo isn't specified, the current culture's
 // NumberFormatInfo is assumed.
 //
 public static int Parse(string s, IFormatProvider?provider)
 {
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider)));
 }
Exemple #11
0
 // Parses an integer from a String in the given style.  If
 // a NumberFormatInfo isn't specified, the current culture's
 // NumberFormatInfo is assumed.
 //
 public static int Parse(String s, NumberStyles style, IFormatProvider provider)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseInt32(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider)));
 }
Exemple #12
0
 public static int Parse(string s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseInt32(s, style, NumberFormatInfo.CurrentInfo));
 }
Exemple #13
0
        // Parses an unsigned byte from a String in the given style.  If
        // a NumberFormatInfo isn't specified, the current culture's
        // NumberFormatInfo is assumed.
        //| <include path='docs/doc[@for="Byte.Parse3"]/*' />
        public static byte Parse(String s, NumberStyles style)
        {
            NumberFormatInfo.ValidateParseStyle(style);
            int i = Number.ParseInt32(s, style);

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException("Overflow_Byte");
            }
            return((byte)i);
        }
Exemple #14
0
        // Parses an unsigned byte from a String in the given style.  If
        // a NumberFormatInfo isn't specified, the current culture's
        // NumberFormatInfo is assumed.
        /// <include file='doc\Byte.uex' path='docs/doc[@for="Byte.Parse3"]/*' />
        public static byte Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);

            NumberFormatInfo.ValidateParseStyle(style);
            int i = Number.ParseInt32(s, style, info);

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
            }
            return((byte)i);
        }
Exemple #15
0
        public static sbyte Parse(String s, NumberStyles style)
        {
            NumberFormatInfo.ValidateParseStyle(style);
            int i = Number.ParseInt32(s, style);

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

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException("Overflow_SByte");
            }
            return((sbyte)i);
        }
        private static byte Parse(String s, NumberStyles style, NumberFormatInfo info)
        {
            int i = 0;

            try {
                i = Number.ParseInt32(s, style, info);
            }
            catch (OverflowException e) {
                throw new OverflowException(Environment.GetResourceString("Overflow_Byte"), e);
            }

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
            }
            return((byte)i);
        }
Exemple #17
0
        private static byte Parse(string s, NumberStyles style, NumberFormatInfo info)
        {
            int int32;

            try
            {
                int32 = Number.ParseInt32(s, style, info);
            }
            catch (OverflowException ex)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Byte"), (Exception)ex);
            }
            if (int32 < 0 || int32 > (int)byte.MaxValue)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
            }
            return((byte)int32);
        }
Exemple #18
0
        public static sbyte Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);

            NumberFormatInfo.ValidateParseStyle(style);
            int i = Number.ParseInt32(s, style, info);

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

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
            }
            return((sbyte)i);
        }
Exemple #19
0
        private static byte Parse(string s, NumberStyles style, NumberFormatInfo info)
        {
            int num = 0;

            try
            {
                num = Number.ParseInt32(s, style, info);
            }
            catch (OverflowException exception)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Byte"), exception);
            }
            if ((num < 0) || (num > 0xff))
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
            }
            return((byte)num);
        }
Exemple #20
0
        private static byte Parse(ReadOnlySpan <char> s, NumberStyles style, NumberFormatInfo info)
        {
            int i = 0;

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

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(SR.Overflow_Byte);
            }
            return((byte)i);
        }
Exemple #21
0
        //| <include path='docs/doc[@for="Int16.Parse3"]/*' />
        public static short Parse(String s, NumberStyles style)
        {
            NumberFormatInfo.ValidateParseStyle(style);

            int i = Number.ParseInt32(s, style);

            // 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) && (i <= UInt16.MaxValue)) // We are parsing a hexadecimal number
            {
                return((short)i);
            }

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException("Overflow_Int16");
            }
            return((short)i);
        }
Exemple #22
0
 public static int Parse(String s)
 {
     return(Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo));
 }
 public static int Parse(string s, NumberStyles style, IFormatProvider provider)
 {
     NumberFormatInfo2.ValidateParseStyleInteger(style);
     return(Number.ParseInt32(s, style, NumberFormatInfo.GetInstance(provider)));
 }
Exemple #24
0
        // Parses an integer from a String in the given style.  If
        // a NumberFormatInfo isn't specified, the current culture's
        // NumberFormatInfo is assumed.
        //
        /// <include file='doc\Int32.uex' path='docs/doc[@for="Int32.Parse2"]/*' />
        public static int Parse(String s, IFormatProvider provider)
        {
            NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);

            return(Number.ParseInt32(s, NumberStyles.Integer, info));
        }
Exemple #25
0
 public static int Parse(ReadOnlySpan <char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider?provider = null)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     return(Number.ParseInt32(s, style, NumberFormatInfo.GetInstance(provider)));
 }
Exemple #26
0
 //| <include path='docs/doc[@for="Int32.Parse"]/*' />
 public static int Parse(String s)
 {
     return(Number.ParseInt32(s, NumberStyles.Integer));
 }
Exemple #27
0
 public static int Parse(String s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     return(Number.ParseInt32(s, style, NumberFormatInfo.CurrentInfo));
 }
 public static int Parse(string s, IFormatProvider provider)
 {
     return(Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider)));
 }