Store Description value of ConfigurationProperty
authorRoma Marusyk <romamarusyk@gmail.com>
Wed, 16 Oct 2019 23:47:53 +0000 (02:47 +0300)
committerJeremy Kuhne <jeremy.kuhne@microsoft.com>
Thu, 17 Oct 2019 02:46:59 +0000 (19:46 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/b9186cfa3566ee24e5f16e45c542a3078e128dc6

src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationProperty.cs
src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/ConfigurationPropertyTests.cs

index b809412..7742d87 100644 (file)
@@ -22,7 +22,7 @@ namespace System.Configuration
         {
             object defaultValue = null;
 
-            ConstructorInit(name, type, ConfigurationPropertyOptions.None, null, null);
+            ConstructorInit(name, type, ConfigurationPropertyOptions.None, null, null, null);
 
             if (type == typeof(string))
             {
@@ -61,7 +61,7 @@ namespace System.Configuration
             ConfigurationPropertyOptions options,
             string description)
         {
-            ConstructorInit(name, type, options, validator, typeConverter);
+            ConstructorInit(name, type, options, validator, typeConverter, description);
 
             SetDefaultValue(defaultValue);
         }
@@ -147,19 +147,16 @@ namespace System.Configuration
                 info.PropertyType,
                 propertyAttribute.Options,
                 validator,
-                typeConverter);
+                typeConverter,
+                descriptionAttribute?.Description);
 
             // Figure out the default value
             InitDefaultValueFromTypeInfo(propertyAttribute, defaultValueAttribute);
-
-            // Get the description
-            if (!string.IsNullOrEmpty(descriptionAttribute?.Description))
-                Description = descriptionAttribute.Description;
         }
 
         public string Name { get; private set; }
 
-        public string Description { get; }
+        public string Description { get; private set; }
 
         internal string ProvidedName { get; private set; }
 
@@ -216,7 +213,8 @@ namespace System.Configuration
             Type type,
             ConfigurationPropertyOptions options,
             ConfigurationValidatorBase validator,
-            TypeConverter converter)
+            TypeConverter converter,
+            string description)
         {
             if (typeof(ConfigurationSection).IsAssignableFrom(type))
             {
@@ -237,6 +235,7 @@ namespace System.Configuration
             }
 
             Name = name;
+            Description = description;
             Type = type;
             _options = options;
             Validator = validator;
index e4b6bac..1f94006 100644 (file)
@@ -138,6 +138,15 @@ namespace System.ConfigurationTests
             Assert.IsType<DummyCanConverter>(property.Converter);
         }
 
+        [Fact]
+        public void DescriptionValueIsExposed()
+        {
+            FooFailsValidator validator = new FooFailsValidator();
+            DummyCanConverter converter = new DummyCanConverter();
+            ConfigurationProperty property = new ConfigurationProperty("foo", typeof(MyConvertableClass), null, converter, validator, ConfigurationPropertyOptions.None, "bar");
+            Assert.Equal("bar", property.Description);
+        }
+
         [TypeConverter(typeof(DummyCantConverter))]
         public class MyUnconvertableClass
         {