ToString's now using IntegerFormatter
[mono.git] / mcs / class / corlib / System / UInt32.cs
1 //
2 // System.UInt32.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System.Globalization;
11
12 namespace System {
13         
14         public struct UInt32 : IComparable, IFormattable { //, IConvertible {
15                 public static Type Type = typeof (uint);
16
17                 public const uint MaxValue = 0xffffffff;
18                 public const uint MinValue = 0;
19                 
20                 public uint value;
21
22                 public int CompareTo (object v)
23                 {
24                         if (!(v is System.UInt32))
25                                 throw new ArgumentException ("Value is not a System.UInt32");
26
27                         if (value == (uint) v)
28                                 return 0;
29
30                         if (value < (uint) v)
31                                 return -1;
32
33                         return 1;
34                 }
35
36                 public override bool Equals (object o)
37                 {
38                         if (!(o is System.UInt32))
39                                 return false;
40
41                         return ((uint) o) == value;
42                 }
43
44                 public override int GetHashCode ()
45                 {
46                         return (int) value;
47                 }
48
49                 public static uint Parse (string s)
50                 {
51                         return Parse (s, NumberStyles.Integer, null);
52                 }
53
54                 public static uint Parse (string s, IFormatProvider fp)
55                 {
56                         return Parse (s, NumberStyles.Integer, fp);
57                 }
58
59                 public static uint Parse (string s, NumberStyles style)
60                 {
61                         return Parse (s, style, null);
62                 }
63                 
64                 public static uint Parse (string s, NumberStyles style, IFormatProvider fp)
65                 {
66                         // TODO: Implement me
67                         return 0;
68                 }
69
70                 public override string ToString ()
71                 {
72                         return ToString ("G", null);
73                 }
74
75                 public string ToString (IFormatProvider fp)
76                 {
77                         return ToString ("G", fp);
78                 }
79
80                 public string ToString (string format)
81                 {
82                         return ToString (format, null);
83                 }
84
85                 public string ToString (string format, IFormatProvider fp)
86                 {
87                         string fmt;
88                         NumberFormatInfo nfi;
89                         
90                         fmt = (format == null) ? "G" : format;
91                         
92                         if (fp == null)
93                                 nfi = NumberFormatInfo.CurrentInfo;
94                         else {
95                                 nfi = (NumberFormatInfo) fp.GetFormat (Type);
96                                 
97                                 if (nfi == null)
98                                         nfi = NumberFormatInfo.CurrentInfo;
99                         }
100
101                         return IntegerFormatter.NumberToString (fmt, nfi, value);
102                 }
103
104                 // =========== IConvertible Methods =========== //
105
106                 public TypeCode GetTypeCode ()
107                 {
108                         return TypeCode.UInt32;
109                 }                               
110         }
111 }