2001-11-28 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / class / corlib / System / UInt64.cs
index 5757149ea3fc668a97bb156382746dcd6f7cafe7..c5fe1a2f89bbdcd5520998d78bf2a8814fbc5d76 100644 (file)
@@ -7,20 +7,34 @@
 // (C) Ximian, Inc.  http://www.ximian.com
 //
 
+using System.Globalization;
+
 namespace System {
-       
-       public struct UInt64 : ValueType, IComparable, IFormattable {
-               public const ulong MinValue = 0;
+
+       [CLSCompliant(false)]
+       public struct UInt64 : IComparable, IFormattable { //, IConvertible {
+               private static Type Type = typeof (ulong);
+
                public const ulong MaxValue = 0xffffffffffffffff;
+               public const ulong MinValue = 0;
                
-               ulong value;
+               public ulong value;
 
                public int CompareTo (object v)
                {
-                       if (!(value is System.UInt64))
-                               throw new ArgumentException ("Value is not a System.UInt64");
+                       if (v == null)
+                               return 1;
+
+                       if (!(v is System.UInt64))
+                               throw new ArgumentException (Locale.GetText ("Value is not a System.UInt64"));
 
-                       return value - (long) v;
+                       if (value == (ulong) v)
+                               return 0;
+
+                       if (value < (ulong) v)
+                               return -1;
+
+                       return 1;
                }
 
                public override bool Equals (object o)
@@ -33,61 +47,69 @@ namespace System {
 
                public override int GetHashCode ()
                {
-                       return (value & 0xffffffff) ^ (value >> 32);
-               }
-
-               public TypeCode GetTypeCode ()
-               {
-                       return TypeCode.UInt64;
+                       return (int)(value & 0xffffffff) ^ (int)(value >> 32);
                }
 
                public static ulong Parse (string s)
                {
-                       // TODO: Implement me
-                       return 0;
+                       return Parse (s, NumberStyles.Integer, null);
                }
 
-               public static ulong Parse (string s, IFormatProvider)
+               public static ulong Parse (string s, IFormatProvider fp)
                {
-                       // TODO: Implement me
-                       return 0;
+                       return Parse (s, NumberStyles.Integer, fp);
                }
 
-               public static ulong Parse (string s, NumberStyles s, fp)
+               public static ulong Parse (string s, NumberStyles style)
                {
-                       // TODO: Implement me
-                       return 0;
+                       return Parse (s, style, null);
                }
 
-               public static ulong Parse (string s, NumberStyles s, IFormatProvider fp)
+               public static ulong Parse (string s, NumberStyles style, IFormatProvider fp)
                {
                        // TODO: Implement me
-                       return 0;
+                       throw new NotImplementedException ();
                }
 
                public override string ToString ()
                {
-                       // TODO: Implement me
-
-                       return "";
+                       return ToString ("G", null);
                }
 
                public string ToString (IFormatProvider fp)
                {
-                       // TODO: Implement me.
-                       return "";
+                       return ToString ("G", fp);
                }
 
                public string ToString (string format)
                {
-                       // TODO: Implement me.
-                       return "";
+                       return ToString (format, null);
                }
 
                public string ToString (string format, IFormatProvider fp)
                {
-                       // TODO: Implement me.
-                       return "";
+                       string fmt;
+                       NumberFormatInfo nfi;
+                       
+                       fmt = (format == null) ? "G" : format;
+                       
+                       if (fp == null)
+                               nfi = NumberFormatInfo.CurrentInfo;
+                       else {
+                               nfi = (NumberFormatInfo) fp.GetFormat (Type);
+                               
+                               if (nfi == null)
+                                       nfi = NumberFormatInfo.CurrentInfo;
+                       }
+
+                       return IntegerFormatter.NumberToString (fmt, nfi, value);
+               }
+
+               // =========== IConvertible Methods =========== //
+
+               public TypeCode GetTypeCode ()
+               {
+                       return TypeCode.UInt64;
                }
        }
 }