5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
10 using System.Globalization;
15 public struct UInt64 : IComparable, IFormattable, IConvertible {
16 public const ulong MaxValue = 0xffffffffffffffff;
17 public const ulong MinValue = 0;
21 public int CompareTo (object v)
26 if (!(v is System.UInt64))
27 throw new ArgumentException (Locale.GetText ("Value is not a System.UInt64"));
29 if (value == (ulong) v)
32 if (value < (ulong) v)
38 public override bool Equals (object o)
40 if (!(o is System.UInt64))
43 return ((ulong) o) == value;
46 public override int GetHashCode ()
48 return (int)(value & 0xffffffff) ^ (int)(value >> 32);
52 public static ulong Parse (string s)
54 return Parse (s, NumberStyles.Integer, null);
58 public static ulong Parse (string s, IFormatProvider fp)
60 return Parse (s, NumberStyles.Integer, fp);
64 public static ulong Parse (string s, NumberStyles style)
66 return Parse (s, style, null);
70 public static ulong Parse (string s, NumberStyles style, IFormatProvider fp)
75 bool digits_seen = false;
78 throw new ArgumentNullException (Locale.GetText ("s is null"));
84 if ((style & NumberStyles.AllowLeadingWhite) != 0)
85 for (i = 0; i < len; i++){
87 if (!Char.IsWhiteSpace (c))
92 throw new FormatException ();
94 if ((style & NumberStyles.AllowLeadingSign) != 0 && (s [i] == '+'))
100 if ((style & NumberStyles.AllowHexSpecifier) != 0) {
101 if (c >= '0' && c <= '9') {
102 uint d = (uint) (c - '0');
103 val = checked (val * 16 + d);
105 } else if (c >= 'a' && c <= 'f') {
106 uint d = (uint) (c - 'a');
107 val = checked (val * 16 + 10 + d);
109 } else if (c >= 'A' && c <= 'F') {
110 uint d = (uint) (c - 'A');
111 val = checked (val * 16 + 10 + d);
115 } else if (c >= '0' && c <= '9'){
116 uint d = (uint) (c - '0');
118 val = checked (val * 10 + d);
125 throw new FormatException ();
127 if ((style & NumberStyles.AllowTrailingWhite) != 0 && Char.IsWhiteSpace (s [i])){
128 for (i++; i < len; i++){
129 if (!Char.IsWhiteSpace (s [i]))
130 throw new FormatException ();
133 throw new FormatException ();
140 public override string ToString ()
142 return ToString (null, null);
145 public string ToString (IFormatProvider fp)
147 return ToString (null, fp);
150 public string ToString (string format)
152 return ToString (format, null);
155 public string ToString (string format, IFormatProvider fp)
157 NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
159 if ( format == null )
162 return IntegerFormatter.NumberToString(format, nfi, value);
165 // =========== IConvertible Methods =========== //
167 public TypeCode GetTypeCode ()
169 return TypeCode.UInt64;
171 public bool ToBoolean (IFormatProvider provider)
173 return System.Convert.ToBoolean (value);
175 public byte ToByte (IFormatProvider provider)
177 return System.Convert.ToByte (value);
179 public char ToChar (IFormatProvider provider)
181 return System.Convert.ToChar (value);
183 public DateTime ToDateTime (IFormatProvider provider)
185 throw new NotImplementedException ();
187 public decimal ToDecimal (IFormatProvider provider)
189 return System.Convert.ToDecimal (value);
191 public double ToDouble (IFormatProvider provider)
193 return System.Convert.ToDouble (value);
195 public short ToInt16 (IFormatProvider provider)
197 return System.Convert.ToInt16 (value);
199 public int ToInt32 (IFormatProvider provider)
201 return System.Convert.ToInt32 (value);
203 public long ToInt64 (IFormatProvider provider)
205 return System.Convert.ToInt64 (value);
207 [CLSCompliant(false)]
208 public sbyte ToSByte (IFormatProvider provider)
210 return System.Convert.ToSByte (value);
212 public float ToSingle (IFormatProvider provider)
214 return System.Convert.ToSingle (value);
216 public object ToType (Type conversionType, IFormatProvider provider)
218 throw new NotImplementedException ();
220 [CLSCompliant(false)]
221 public ushort ToUInt16 (IFormatProvider provider)
223 return System.Convert.ToUInt16 (value);
225 [CLSCompliant(false)]
226 public uint ToUInt32 (IFormatProvider provider)
228 return System.Convert.ToUInt32 (value);
230 [CLSCompliant(false)]
231 public ulong ToUInt64 (IFormatProvider provider)