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

Store Description value of ConfigurationProperty #41842

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,15 @@ public void TypeConverterRecognized()
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
{
Expand Down