Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Store Description value of ConfigurationProperty 2 (#41873)
Browse files Browse the repository at this point in the history
* Store Description value of ConfigurationProperty

* Skip test on the .NET Framework
  • Loading branch information
Marusyk authored and ViktorHofer committed Oct 18, 2019
1 parent 296bbb0 commit 2b92fc0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ConfigurationProperty(string name, Type type)
{
object defaultValue = null;

ConstructorInit(name, type, ConfigurationPropertyOptions.None, null, null);
ConstructorInit(name, type, ConfigurationPropertyOptions.None, null, null, null);

if (type == typeof(string))
{
Expand Down Expand Up @@ -61,7 +61,7 @@ public ConfigurationProperty(string name, Type type, object defaultValue, Config
ConfigurationPropertyOptions options,
string description)
{
ConstructorInit(name, type, options, validator, typeConverter);
ConstructorInit(name, type, options, validator, typeConverter, description);

SetDefaultValue(defaultValue);
}
Expand Down Expand Up @@ -147,19 +147,16 @@ internal ConfigurationProperty(PropertyInfo info)
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; }

Expand Down Expand Up @@ -216,7 +213,8 @@ public TypeConverter Converter
Type type,
ConfigurationPropertyOptions options,
ConfigurationValidatorBase validator,
TypeConverter converter)
TypeConverter converter,
string description)
{
if (typeof(ConfigurationSection).IsAssignableFrom(type))
{
Expand All @@ -237,6 +235,7 @@ public TypeConverter Converter
}

Name = name;
Description = description;
Type = type;
_options = options;
Validator = validator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ public void TypeConverterRecognized()
Assert.IsType<DummyCanConverter>(property.Converter);
}

[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Full framework does not have the fix #41873")]
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
{
Expand Down

0 comments on commit 2b92fc0

Please sign in to comment.