X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem%2FByte.cs;h=ae039affd3b59576657e7ca3651a10ee2211e626;hb=a0173a7e76ad48889ade46116e516731b170e7c5;hp=1bbf78ac7f4aa519273640c854dc4f48b2a6c289;hpb=a3ea7ceb4d4f5e2cb8ea421313e8939640fb898c;p=mono.git diff --git a/mcs/class/corlib/System/Byte.cs b/mcs/class/corlib/System/Byte.cs index 1bbf78ac7f4..ae039affd3b 100644 --- a/mcs/class/corlib/System/Byte.cs +++ b/mcs/class/corlib/System/Byte.cs @@ -35,10 +35,8 @@ using System.Globalization; namespace System { [Serializable] - public struct Byte : IFormattable, IConvertible, IComparable -#if NET_2_0 - , IComparable, IEquatable -#endif + [System.Runtime.InteropServices.ComVisible (true)] + public struct Byte : IFormattable, IConvertible, IComparable, IComparable, IEquatable { public const byte MinValue = 0; public const byte MaxValue = 255; @@ -53,14 +51,7 @@ namespace System if (!(value is System.Byte)) throw new ArgumentException (Locale.GetText ("Value is not a System.Byte.")); - byte xv = (byte) value; - - if (m_value == xv) - return 0; - if (m_value > xv) - return 1; - else - return -1; + return CompareTo ((byte) value); } public override bool Equals (object obj) @@ -76,111 +67,14 @@ namespace System return m_value; } -#if NET_2_0 public int CompareTo (byte value) { - if (m_value == value) - return 0; - if (m_value > value) - return 1; - else - return -1; - } - - public bool Equals (byte value) - { - return value == m_value; + return m_value - value; } -#endif - internal static bool Parse (string s, bool tryParse, out byte result, out Exception exc) + public bool Equals (byte obj) { - byte val = 0; - int len; - int i; - bool digits_seen = false; - bool negative = false; - - result = 0; - exc = null; - - if (s == null) { - if (!tryParse) - exc = new ArgumentNullException ("s"); - return false; - } - - len = s.Length; - - // look for the first non-whitespace character - char c; - for (i = 0; i < len; i++){ - c = s [i]; - if (!Char.IsWhiteSpace (c)) - break; - } - - // if it's all whitespace, then throw exception - if (i == len) { - if (!tryParse) - exc = Int32.GetFormatException (); - return false; - } - - // look for the optional '+' sign - if (s [i] == '+') - i++; - else if (s [i] == '-') { - negative = true; - i++; - } - - // we should just have numerals followed by whitespace now - for (; i < len; i++){ - c = s [i]; - - if (c >= '0' && c <= '9'){ - // shift left and accumulate every time we find a numeral - byte d = (byte) (c - '0'); - - val = checked ((byte) (val * 10 + d)); - digits_seen = true; - } else { - // after the last numeral, only whitespace is allowed - if (Char.IsWhiteSpace (c)){ - for (i++; i < len; i++){ - if (!Char.IsWhiteSpace (s [i])) { - if (!tryParse) - exc = Int32.GetFormatException (); - return false; - } - } - break; - } else { - if (!tryParse) - exc = Int32.GetFormatException (); - return false; - } - } - } - - // -0 is legal but other negative values are not - if (negative && (val > 0)) { - if (!tryParse) - exc = new OverflowException ( - Locale.GetText ("Negative number")); - return false; - } - - // if all we had was a '+' sign, then throw exception - if (!digits_seen) { - if (!tryParse) - exc = Int32.GetFormatException (); - return false; - } - - result = val; - return true; + return m_value == obj; } public static byte Parse (string s, IFormatProvider provider) @@ -196,33 +90,20 @@ namespace System public static byte Parse (string s, NumberStyles style, IFormatProvider provider) { uint tmpResult = UInt32.Parse (s, style, provider); - if (tmpResult > Byte.MaxValue || tmpResult < Byte.MinValue) - throw new OverflowException (Locale.GetText ("Value too large or too small.")); + if (tmpResult > Byte.MaxValue) + throw new OverflowException (Locale.GetText ("Value too large.")); return (byte) tmpResult; } public static byte Parse (string s) { - Exception exc; - byte res; - - if (!Parse (s, false, out res, out exc)) - throw exc; - - return res; + return Parse (s, NumberStyles.Integer, null); } -#if NET_2_0 public static bool TryParse (string s, out byte result) { - Exception exc; - if (!Parse (s, true, out result, out exc)) { - result = 0; - return false; - } - - return true; + return TryParse (s, NumberStyles.Integer, null, out result); } public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out byte result) @@ -233,17 +114,16 @@ namespace System if (!UInt32.TryParse (s, style, provider, out tmpResult)) return false; - if (tmpResult > Byte.MaxValue || tmpResult < Byte.MinValue) + if (tmpResult > Byte.MaxValue) return false; result = (byte)tmpResult; return true; } -#endif public override string ToString () { - return NumberFormatter.FormatGeneral (new NumberFormatter.NumberStore (m_value)); + return NumberFormatter.NumberToString (m_value, null); } public string ToString (string format) @@ -253,13 +133,12 @@ namespace System public string ToString (IFormatProvider provider) { - return NumberFormatter.FormatGeneral (new NumberFormatter.NumberStore (m_value), provider); + return NumberFormatter.NumberToString (m_value, provider); } public string ToString (string format, IFormatProvider provider) { - NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider); - return NumberFormatter.NumberToString (format, m_value, nfi); + return NumberFormatter.NumberToString (format, m_value, provider); } // =========== IConvertible Methods =========== // @@ -268,9 +147,11 @@ namespace System return TypeCode.Byte; } - object IConvertible.ToType (Type conversionType, IFormatProvider provider) + object IConvertible.ToType (Type targetType, IFormatProvider provider) { - return System.Convert.ToType (m_value, conversionType, provider); + if (targetType == null) + throw new ArgumentNullException ("targetType"); + return System.Convert.ToType (m_value, targetType, provider, false); } bool IConvertible.ToBoolean (IFormatProvider provider) @@ -328,13 +209,6 @@ namespace System return System.Convert.ToSingle (m_value); } -/* - string IConvertible.ToString (IFormatProvider provider) - { - return ToString("G", provider); - } -*/ - ushort IConvertible.ToUInt16 (IFormatProvider provider) { return System.Convert.ToUInt16 (m_value);