From 6c99c56018ffc1a1a920a6977b03ad7fac3d4052 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Wed, 5 Feb 2014 15:03:23 +0100 Subject: [PATCH] [corlib] Add nullable tests --- mcs/class/corlib/System/Nullable.cs | 7 ++-- mcs/class/corlib/Test/System/NullableTest.cs | 44 ++++++++++++++++++++ mcs/class/corlib/corlib_test.dll.sources | 1 + 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 mcs/class/corlib/Test/System/NullableTest.cs diff --git a/mcs/class/corlib/System/Nullable.cs b/mcs/class/corlib/System/Nullable.cs index 86a7bd7d4a4..11f6c67dbd4 100644 --- a/mcs/class/corlib/System/Nullable.cs +++ b/mcs/class/corlib/System/Nullable.cs @@ -74,10 +74,9 @@ namespace System { 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; } } diff --git a/mcs/class/corlib/Test/System/NullableTest.cs b/mcs/class/corlib/Test/System/NullableTest.cs new file mode 100644 index 00000000000..1ec8201e721 --- /dev/null +++ b/mcs/class/corlib/Test/System/NullableTest.cs @@ -0,0 +1,44 @@ +// +// NullableTest.cs +// +// Authors: +// Marek Safar +// +// Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using NUnit.Framework; + +namespace MonoTests.System +{ + [TestFixture] + public class NullableTest + { + [Test] + public void GetUnderlyingType () + { + Assert.AreSame (typeof (int), Nullable.GetUnderlyingType (typeof (Nullable)), "#1"); + Assert.IsNull (Nullable.GetUnderlyingType (typeof (Nullable<>)), "#2"); + } + } +} diff --git a/mcs/class/corlib/corlib_test.dll.sources b/mcs/class/corlib/corlib_test.dll.sources index 5cd15e5de42..e3658887ee4 100644 --- a/mcs/class/corlib/corlib_test.dll.sources +++ b/mcs/class/corlib/corlib_test.dll.sources @@ -22,6 +22,7 @@ System/CharEnumeratorTest.cs System/CharTest.cs System/DelegateTest.cs System/ModuleHandleTest.cs +System/NullableTest.cs System/ObsoleteAttributeTest.cs System/IntegerTryParse.cs System/LazyTest.cs -- 2.25.1