//
-// System.Nullable
+// System.Nullable.cs
//
// Martin Baulig (martin@ximian.com)
// Marek Safar (marek.safar@gmail.com)
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0
-
using System.Reflection;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using System.Diagnostics;
namespace System
{
[ComVisible (true)]
public static class Nullable {
- public static int Compare<T> (T? value1, T? value2) where T: struct
+
+#if NET_2_1
+ [ComVisible (false)]
+#endif
+ public static int Compare<T> (T? n1, T? n2) where T: struct
{
- if (value1.has_value) {
- if (!value2.has_value)
+ if (n1.has_value) {
+ if (!n2.has_value)
return 1;
- return Comparer<T>.Default.Compare (value1.value, value2.value);
+ return Comparer<T>.Default.Compare (n1.value, n2.value);
}
- return value2.has_value ? -1 : 0;
+ return n2.has_value ? -1 : 0;
}
- public static bool Equals<T> (T? value1, T? value2) where T: struct
+#if NET_2_1
+ [ComVisible (false)]
+#endif
+ public static bool Equals<T> (T? n1, T? n2) where T: struct
{
- if (value1.has_value != value2.has_value)
+ if (n1.has_value != n2.has_value)
return false;
- if (!value1.has_value)
+ if (!n1.has_value)
return true;
- return EqualityComparer<T>.Default.Equals (value1.value, value2.value);
+ return EqualityComparer<T>.Default.Equals (n1.value, n2.value);
}
public static Type GetUnderlyingType (Type nullableType)
{
if (nullableType == null)
throw new ArgumentNullException ("nullableType");
- if (nullableType.IsGenericType && nullableType.GetGenericTypeDefinition () == typeof (Nullable<>))
- return nullableType.GetGenericArguments ()[0];
- else
- return null;
+
+ return nullableType.IsGenericType && !nullableType.IsGenericTypeDefinition && nullableType.GetGenericTypeDefinition () == typeof(Nullable<>) ?
+ nullableType.GetGenericArguments () [0] : null;
}
}
[Serializable]
+ [DebuggerStepThrough]
public struct Nullable<T> where T: struct
{
#region Sync with runtime code
public T GetValueOrDefault ()
{
- return GetValueOrDefault (default (T));
+ return value;
}
- public T GetValueOrDefault (T def_value)
+ public T GetValueOrDefault (T defaultValue)
{
- if (!has_value)
- return def_value;
- else
- return value;
+ return has_value ? value : defaultValue;
}
public override string ToString ()
//
// These are called by the JIT
//
-
+#pragma warning disable 169
//
// JIT implementation of box valuetype System.Nullable`1<T>
//
return null;
return (T) o;
}
+#pragma warning restore 169
}
}
-#endif