From: Bart Vries Date: Thu, 2 Jan 2014 23:15:52 +0000 (+0100) Subject: Implementation of System.Reflection.ParameterInfo.HasDefaultValue X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=3d1779302ea67acae84b1f10aba3d3a725866d74;p=mono.git Implementation of System.Reflection.ParameterInfo.HasDefaultValue --- diff --git a/mcs/class/corlib/System.Reflection/MonoParameterInfo.cs b/mcs/class/corlib/System.Reflection/MonoParameterInfo.cs index 327166e4488..ce4fdda324c 100644 --- a/mcs/class/corlib/System.Reflection/MonoParameterInfo.cs +++ b/mcs/class/corlib/System.Reflection/MonoParameterInfo.cs @@ -236,5 +236,20 @@ namespace System.Reflection return Type.EmptyTypes; return types; } + +#if NET_4_5 + public override bool HasDefaultValue { + get { + object defaultValue = DefaultValue; + if (defaultValue == null) + return true; + + if (defaultValue.GetType () == typeof(DBNull) || defaultValue.GetType () == typeof(Missing)) + return false; + + return true; + } + } +#endif } } diff --git a/mcs/class/corlib/System.Reflection/ParameterInfo.cs b/mcs/class/corlib/System.Reflection/ParameterInfo.cs index 890dffd3b2f..1c00fb96c10 100644 --- a/mcs/class/corlib/System.Reflection/ParameterInfo.cs +++ b/mcs/class/corlib/System.Reflection/ParameterInfo.cs @@ -193,8 +193,7 @@ namespace System.Reflection public virtual IEnumerable CustomAttributes { get { return GetCustomAttributesData (); } } - - [MonoTODO] + public virtual bool HasDefaultValue { get { throw new NotImplementedException (); } } diff --git a/mcs/class/corlib/Test/System.Reflection/ParameterInfoTest.cs b/mcs/class/corlib/Test/System.Reflection/ParameterInfoTest.cs index ff1d915632d..b22f46f3650 100644 --- a/mcs/class/corlib/Test/System.Reflection/ParameterInfoTest.cs +++ b/mcs/class/corlib/Test/System.Reflection/ParameterInfoTest.cs @@ -98,6 +98,15 @@ namespace MonoTests.System.Reflection Assert.AreEqual (ParamEnum.Foo, info [5].DefaultValue, "#2"); } +#if NET_4_5 + [Test] + public void HasDefaultValueEnum () { + ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters (); + + Assert.IsTrue (info [5].HasDefaultValue); + } +#endif + public static void Sample2 ([DecimalConstantAttribute(2,2,2,2,2)] decimal a, [DateTimeConstantAttribute(123456)] DateTime b) {} [Test] @@ -117,7 +126,19 @@ namespace MonoTests.System.Reflection Assert.AreEqual (pi [1].DefaultValue.GetType (), typeof (Missing), "#2"); } - public void Sample (int a, [Optional] int b) +#if NET_4_5 + [Test] + public void TestHasDefaultValues () + { + ParameterInfo [] pi = typeof (ParameterInfoTest).GetMethod ("Sample").GetParameters (); + + Assert.IsFalse (pi [0].HasDefaultValue, "#1"); + Assert.IsFalse (pi [1].HasDefaultValue, "#2"); + Assert.IsTrue (pi [2].HasDefaultValue, "#3"); + } +#endif + + public void Sample (int a, [Optional] int b, object c = null) { } @@ -235,6 +256,14 @@ namespace MonoTests.System.Reflection Assert.AreEqual (decimal.MaxValue, info [0].DefaultValue); } +#if NET_4_5 + [Test] + public void HasDefaultValueDecimal () { + var info = typeof (ParameterInfoTest).GetMethod ("TestC").GetParameters (); + Assert.IsTrue (info [0].HasDefaultValue); + } +#endif + class MyParameterInfo2 : ParameterInfo { public ParameterAttributes MyAttrsImpl;