Merge pull request #819 from brendanzagaeski/patch-1
[mono.git] / mcs / class / corlib / System / Nullable.cs
index 4ea9ed80735864a5e942936c72c842610f2ac005..11f6c67dbd4e4d73c69b0a3b4a007025069ea7bd 100644 (file)
@@ -1,5 +1,5 @@
 //
-// 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
@@ -133,15 +139,12 @@ namespace System
 
                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 ()
@@ -165,7 +168,7 @@ namespace System
                //
                // These are called by the JIT
                //
-               
+#pragma warning disable 169
                //
                // JIT implementation of box valuetype System.Nullable`1<T>
                //
@@ -183,6 +186,6 @@ namespace System
                                return null;
                        return (T) o;
                }
+#pragma warning restore 169
        }
 }
-#endif