From 1c4a35efc3b536a9a0e2726a67fd1d56baa590e2 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Fri, 18 Jan 2019 17:22:58 +0300 Subject: [PATCH] Add TypeConverter fallback to DefaultValueAttribute (#12412) Requires https://github.com/mono/corefx/pull/235. Fixes https://github.com/mono/mono/issues/12362. --- external/corefx | 2 +- .../DefaultValueAttributeTest.cs | 19 +++++++++++++++++++ .../compmod/system/componentmodel/TypeDescriptor.cs | 8 ++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/external/corefx b/external/corefx index 7d84ec4c2de..b5f6e2e5e35 160000 --- a/external/corefx +++ b/external/corefx @@ -1 +1 @@ -Subproject commit 7d84ec4c2de2555207ab19ec46159fd060cec890 +Subproject commit b5f6e2e5e35a9677080ad4c0a38dd46e6f46532f diff --git a/mcs/class/System/Test/System.ComponentModel/DefaultValueAttributeTest.cs b/mcs/class/System/Test/System.ComponentModel/DefaultValueAttributeTest.cs index 6eac761bfc2..4fa9bfcbed5 100644 --- a/mcs/class/System/Test/System.ComponentModel/DefaultValueAttributeTest.cs +++ b/mcs/class/System/Test/System.ComponentModel/DefaultValueAttributeTest.cs @@ -26,6 +26,9 @@ using System; using System.ComponentModel; +#if !FULL_AOT_RUNTIME +using System.Drawing; +#endif using NUnit.Framework; namespace MonoTests.System.ComponentModel { @@ -58,5 +61,21 @@ namespace MonoTests.System.ComponentModel { Assert.AreEqual (1, dvat.GetHashCode (), "GetHashCode"); } + +#if !FULL_AOT_RUNTIME + [DefaultValue (typeof (Color), "Black")] + public Color Bar { get; set; } + + // https://github.com/mono/mono/issues/12362 + [Test] + public void Bug_12362 () + { + var prop = typeof (DefaultValueAttributeTest).GetProperty ("Bar"); + var attr = (DefaultValueAttribute)prop.GetCustomAttributes (true) [0]; + var value = attr.Value; + Assert.IsNotNull (value); + Assert.AreEqual (typeof (Color), value.GetType ()); + } +#endif } } diff --git a/mcs/class/referencesource/System/compmod/system/componentmodel/TypeDescriptor.cs b/mcs/class/referencesource/System/compmod/system/componentmodel/TypeDescriptor.cs index 0783e121a8b..bef650013df 100644 --- a/mcs/class/referencesource/System/compmod/system/componentmodel/TypeDescriptor.cs +++ b/mcs/class/referencesource/System/compmod/system/componentmodel/TypeDescriptor.cs @@ -1557,6 +1557,14 @@ namespace System.ComponentModel return converter; } +#if MONO // from https://github.com/dotnet/corefx/pull/31739 + // This is called by System.ComponentModel.DefaultValueAttribute via reflection. + private static object ConvertFromInvariantString(Type type, string stringValue) + { + return GetConverter(type).ConvertFromInvariantString(stringValue); + } +#endif + /// /// Gets the default event for the specified type of component. /// -- 2.11.4.GIT