5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
10 using System.Globalization;
14 public struct Int16 : IComparable, IFormattable { //, IConvertible {
15 private static Type Type = typeof (short);
17 public const short MaxValue = 32767;
18 public const short MinValue = -32768;
20 // VES needs to know about value. public is workaround
21 // so source will compile
24 public int CompareTo (object v)
29 if (!(v is System.Int16))
30 throw new ArgumentException (Locale.GetText ("Value is not a System.Int16"));
41 public override bool Equals (object o)
43 if (!(o is System.Int16))
46 return ((short) o) == value;
49 public override int GetHashCode ()
54 public static short Parse (string s)
60 bool digits_seen = false;
63 throw new ArgumentNullException (Locale.GetText ("s is null"));
68 for (i = 0; i < len; i++){
70 if (!Char.IsWhiteSpace (c))
75 throw new FormatException ();
88 if (c >= '0' && c <= '9'){
89 val = checked ((short) (val * 10 + (c - '0')));
92 if (Char.IsWhiteSpace (c)){
93 for (i++; i < len; i++){
94 if (!Char.IsWhiteSpace (s [i]))
95 throw new FormatException ();
99 throw new FormatException ();
103 throw new FormatException ();
106 val = checked ((short) -val);
111 public static short Parse (string s, IFormatProvider fp)
113 return Parse (s, NumberStyles.Integer, fp);
116 public static short Parse (string s, NumberStyles style)
118 return Parse (s, style, null);
121 public static short Parse (string s, NumberStyles style, IFormatProvider fp)
123 throw new NotImplementedException ();
126 public override string ToString ()
128 return ToString ("G", null);
131 public string ToString (IFormatProvider fp)
133 return ToString ("G", fp);
136 public string ToString (string format)
138 return ToString (format, null);
141 public string ToString (string format, IFormatProvider fp)
144 NumberFormatInfo nfi;
146 fmt = (format == null) ? "G" : format;
149 nfi = NumberFormatInfo.CurrentInfo;
151 nfi = (NumberFormatInfo) fp.GetFormat (Type);
154 nfi = NumberFormatInfo.CurrentInfo;
157 return IntegerFormatter.NumberToString (fmt, nfi, value);
160 // =========== IConvertible Methods =========== //
162 public TypeCode GetTypeCode ()
164 return TypeCode.Int16;