namespace System {
[Serializable]
-#if NET_2_0
[System.Runtime.InteropServices.ComVisible (true)]
-#endif
- public struct Int16 : IFormattable, IConvertible, IComparable
-#if NET_2_0
- , IComparable<Int16>, IEquatable <Int16>
-#endif
+ public struct Int16 : IFormattable, IConvertible, IComparable, IComparable<Int16>, IEquatable <Int16>
{
public const short MaxValue = 32767;
internal short m_value;
- public int CompareTo (object v)
+ public int CompareTo (object value)
{
- if (v == null)
+ if (value == null)
return 1;
- if (!(v is System.Int16))
+ if (!(value is System.Int16))
throw new ArgumentException (Locale.GetText ("Value is not a System.Int16"));
- short xv = (short) v;
- if (m_value == xv)
- return 0;
- if (m_value > xv)
- return 1;
- else
- return -1;
+ return CompareTo ((short) value);
}
- public override bool Equals (object o)
+ public override bool Equals (object obj)
{
- if (!(o is System.Int16))
+ if (!(obj is System.Int16))
return false;
- return ((short) o) == m_value;
+ return ((short) obj) == m_value;
}
public override int GetHashCode ()
return m_value;
}
-#if NET_2_0
public int CompareTo (short value)
{
- if (m_value == value)
- return 0;
- if (m_value > value)
- return 1;
- else
- return -1;
+ return m_value - value;
}
- public bool Equals (short value)
+ public bool Equals (short obj)
{
- return value == m_value;
+ return obj == m_value;
}
-#endif
internal static bool Parse (string s, bool tryParse, out short result, out Exception exc)
{
return false;
}
- public static short Parse (string s, IFormatProvider fp)
+ public static short Parse (string s, IFormatProvider provider)
{
- return Parse (s, NumberStyles.Integer, fp);
+ return Parse (s, NumberStyles.Integer, provider);
}
public static short Parse (string s, NumberStyles style)
return Parse (s, style, null);
}
- public static short Parse (string s, NumberStyles style, IFormatProvider fp)
+ public static short Parse (string s, NumberStyles style, IFormatProvider provider)
{
- int tmpResult = Int32.Parse (s, style, fp);
- if (tmpResult > Int16.MaxValue || tmpResult < Int16.MinValue)
- throw new OverflowException ("Value too large or too small.");
+ int tmpResult = Int32.Parse (s, style, provider);
+ if ((style & NumberStyles.AllowHexSpecifier) != 0) {
+ if (tmpResult >= 0 && tmpResult <= ushort.MaxValue)
+ return (short) tmpResult;
+ } else if (tmpResult <= MaxValue && tmpResult >= MinValue) {
+ return (short) tmpResult;
+ }
- return (short) tmpResult;
+ throw new OverflowException ("Value too large or too small.");
}
public static short Parse (string s)
return res;
}
-#if NET_2_0
public static bool TryParse (string s, out short result)
{
Exception exc;
result = (short)tmpResult;
return true;
}
-#endif
public override string ToString ()
{
return ToString (format, null);
}
- public string ToString (string format, IFormatProvider fp)
+ public string ToString (string format, IFormatProvider provider)
{
- return NumberFormatter.NumberToString(format, m_value, fp);
+ return NumberFormatter.NumberToString(format, m_value, provider);
}
// =========== IConvertible Methods =========== //
{
return System.Convert.ToSByte (m_value);
}
-
+
float IConvertible.ToSingle (IFormatProvider provider)
{
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)