[corlib] Make primitive types smaller than int compare result compatible
[mono.git] / mcs / class / corlib / System / UInt16.cs
index 3d53bb89405f00ce40389b889faa70e35c9cee2b..42ceeb7205aa99308d3bf731df0415edcb7528f1 100644 (file)
@@ -33,13 +33,8 @@ namespace System
 {
        [Serializable]
        [CLSCompliant (false)]
-#if NET_2_0
        [System.Runtime.InteropServices.ComVisible (true)]
-#endif
-       public struct UInt16 : IFormattable, IConvertible, IComparable
-#if NET_2_0
-               , IComparable<UInt16>, IEquatable <UInt16>
-#endif
+       public struct UInt16 : IFormattable, IConvertible, IComparable, IComparable<UInt16>, IEquatable <UInt16>
        {
                public const ushort MaxValue = 0xffff;
                public const ushort MinValue = 0;
@@ -54,7 +49,7 @@ namespace System
                        if(!(value is System.UInt16))
                                throw new ArgumentException (Locale.GetText ("Value is not a System.UInt16."));
 
-                       return this.m_value - ((ushort) value);
+                       return CompareTo ((ushort) value);
                }
 
                public override bool Equals (object obj)
@@ -70,23 +65,15 @@ namespace System
                        return m_value;
                }
 
-#if NET_2_0
                public int CompareTo (ushort value)
                {
-                       if (m_value == value)
-                               return 0;
-                       if (m_value > value)
-                               return 1;
-                       else
-                               return -1;
+                       return m_value - value;
                }
 
-               public bool Equals (ushort value)
+               public bool Equals (ushort obj)
                {
-                       return value == m_value;
+                       return obj == m_value;
                }
-#endif
-
 
                [CLSCompliant (false)]
                public static ushort Parse (string s, IFormatProvider provider)
@@ -116,7 +103,6 @@ namespace System
                        return Parse (s, NumberStyles.Number, null);
                }
 
-#if NET_2_0
                [CLSCompliant(false)]
                public static bool TryParse (string s, out ushort result) 
                {
@@ -138,17 +124,15 @@ namespace System
                        result = (ushort)tmpResult;
                        return true;
                }
-#endif
 
                public override string ToString ()
                {
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
                public string ToString (IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format)
@@ -158,8 +142,7 @@ namespace System
 
                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 =========== //
@@ -223,9 +206,12 @@ namespace System
                        return System.Convert.ToSingle (m_value);
                }
 
-               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);
                }
 
                ushort IConvertible.ToUInt16 (IFormatProvider provider)