2007-11-14 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / System / Nullable.cs
index 37ce6c9913f40810135c029f13b8da8e2a085b45..b981afb00596bb21fb9788cce4c8513c2a355adc 100644 (file)
@@ -34,9 +34,13 @@ using System.Reflection;
 using System.Collections.Generic;
 #endif
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 
 #if NET_2_0
 namespace System {
+#if NET_2_0
+       [ComVisible (true)]
+#endif
        public static class Nullable {
                public static int Compare<T> (Nullable<T> left, Nullable<T> right) where T: struct
                {
@@ -69,7 +73,8 @@ namespace System {
                }
        }
 
-       public struct Nullable<T> : IComparable, INullableValue where T: struct
+       [Serializable]
+       public struct Nullable<T> where T: struct
        {
                #region Sync with runtime code
                internal T value;
@@ -95,44 +100,26 @@ namespace System {
                        }
                }
 
-               object INullableValue.Value {
-                       get {
-                               return (object)Value;
-                       }
-               }
-               
-               [Obsolete]
-               public int CompareTo (Nullable<T> other)
-               {
-                       return Nullable.Compare<T> (this, other);
-               }
-
-               [Obsolete]
-               public int CompareTo (object other)
-               {
-                       if (!(other is Nullable<T>))
-                               throw new ArgumentException ("Object type can not be converted to target type.");
-
-                       return Nullable.Compare<T> (this, (Nullable<T>) other);
-               }
-
                public override bool Equals (object other)
                {
+                       if (other == null)
+                               return has_value == false;
                        if (!(other is Nullable<T>))
                                return false;
 
                        return Equals ((Nullable <T>) other);
                }
 
-               public bool Equals (Nullable<T> other)
+               bool Equals (Nullable<T> other)
                {
-                       if (other.has_value != has_value)
+                       Nullable<T> no = (Nullable<T>) other;
+                       if (no.has_value != has_value)
                                return false;
 
                        if (has_value == false)
                                return true;
 
-                       return other.value.Equals (value);
+                       return no.value.Equals (value);
                }
 
                public override int GetHashCode ()
@@ -161,7 +148,7 @@ namespace System {
                        if (has_value)
                                return value.ToString ();
                        else
-                               return "";
+                               return String.Empty;
                }
 
                public static implicit operator Nullable<T> (T value)
@@ -174,17 +161,6 @@ namespace System {
                        return value.Value;
                }
 
-               public static bool operator == (Nullable<T> left, Nullable<T> right)
-               {
-                       return left.Equals (right);
-               }
-
-               public static bool operator != (Nullable<T> left, Nullable<T> right)
-               {
-                       return !left.Equals (right);
-               }
-
-
                // These are called by the JIT
                // Ironicly, the C#  code is the same for these two,
                // however, on the inside they do somewhat different things