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