5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
10 using System.Globalization;
14 public struct Int32 : IComparable, IFormattable { //, IConvertible {
15 private static Type Type = typeof (int);
17 public const int MaxValue = 0x7fffffff;
18 public const int MinValue = -2147483648;
22 public int CompareTo (object v)
27 if (!(v is System.Int32))
28 throw new ArgumentException (Locale.GetText ("Value is not a System.Int32"));
39 public override bool Equals (object o)
41 if (!(o is System.Int32))
44 return ((int) o) == value;
47 public override int GetHashCode ()
52 public static int Parse (string s)
58 bool digits_seen = false;
61 throw new ArgumentNullException (Locale.GetText ("s is null"));
66 for (i = 0; i < len; i++){
68 if (!Char.IsWhiteSpace (c))
73 throw new FormatException ();
86 if (c >= '0' && c <= '9'){
87 val = checked (val * 10 + (c - '0'));
90 if (Char.IsWhiteSpace (c)){
91 for (i++; i < len; i++){
92 if (!Char.IsWhiteSpace (s [i]))
93 throw new FormatException ();
97 throw new FormatException ();
101 throw new FormatException ();
109 public static int Parse (string s, IFormatProvider fp)
111 return Parse (s, NumberStyles.Integer, fp);
114 public static int Parse (string s, NumberStyles style)
116 return Parse (s, style, null);
120 public static int Parse (string s, NumberStyles style, IFormatProvider fp)
122 // FIXME: Better than nothing ;-)
124 //throw new NotImplementedException ();
127 public override string ToString ()
129 return ToString ("G", null);
132 public string ToString (IFormatProvider fp)
134 return ToString ("G", fp);
137 public string ToString (string format)
139 return ToString (format, null);
142 public string ToString (string format, IFormatProvider fp)
145 NumberFormatInfo nfi;
147 fmt = (format == null) ? "G" : format;
150 nfi = NumberFormatInfo.CurrentInfo;
152 nfi = (NumberFormatInfo) fp.GetFormat (Type);
155 nfi = NumberFormatInfo.CurrentInfo;
158 return IntegerFormatter.NumberToString (fmt, nfi, value);
161 // =========== IConvertible Methods =========== //
163 public TypeCode GetTypeCode ()
165 return TypeCode.Int32;