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