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)
+ public static int Compare<T> (Nullable<T> left, Nullable<T> right) where T: struct
{
IComparable icomparable = left.value as IComparable;
if (icomparable == null)
return icomparable.CompareTo (right.value);
}
- public static bool Equals<T> (Nullable <T> value1, Nullable<T> value2)
+ public static bool Equals<T> (Nullable <T> value1, Nullable<T> value2) where T: struct
{
return value1.Equals (value2);
}
}
}
- 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;
}
}
- 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 ()
if (has_value)
return value.ToString ();
else
- return "";
+ return String.Empty;
}
public static implicit operator Nullable<T> (T value)
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