Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / class / corlib / System / Nullable.cs
index 9813659e01d014b625ad25cb022017013009bea3..b8ac671d69978cf8fbb0eb06db8344be9e803a99 100644 (file)
 // 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
 {
@@ -45,30 +44,30 @@ namespace System
 #if NET_2_1
                [ComVisible (false)]
 #endif
-               public static int Compare<T> (T? value1, T? value2) where T: struct
+               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;
                }
 
 #if NET_2_1
                [ComVisible (false)]
 #endif
-               public static bool Equals<T> (T? value1, T? value2) where T: struct
+               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)
@@ -83,6 +82,7 @@ namespace System
        }
 
        [Serializable]
+       [DebuggerStepThrough]
        public struct Nullable<T> where T: struct
        {
                #region Sync with runtime code
@@ -140,15 +140,12 @@ namespace System
 
                public T GetValueOrDefault ()
                {
-                       return GetValueOrDefault (default (T));
+                       return has_value ? value : default (T);
                }
 
                public T GetValueOrDefault (T defaultValue)
                {
-                       if (!has_value)
-                               return defaultValue;
-                       else
-                               return value;
+                       return has_value ? value : defaultValue;
                }
 
                public override string ToString ()
@@ -193,4 +190,3 @@ namespace System
 #pragma warning restore 169
        }
 }
-#endif