For each item in my application's settings, I've added text to its Description Property
which I want to retrieve at runtime. I'm sure I'm missing some basic logical nuance here, but everything I've tried has failed. Clearly, my understanding of what value needs to be passed to the Attributes property of the SettingsProperty class is wrong. I'm further confused by the fact that when I iterate through all they keys returned by SettingsProperty.Attributes.Keys, I can see "System.Configuration.SettingsDescriptionAttribute", but when I pass that string in as the key to the Attributes property, null is returned.
Any insight into how to properly retrieve the value Description Property would be very much appreciated. Thanks. :)
public void MyMethod()
{
SettingsPropertyCollection MyAppProperties =
Properties.Settings.Default.Properties;
IEnumerator enumerator = MyAppProperties.GetEnumerator();
// Iterate through all the keys to see what we have....
while (enumerator.MoveNext())
{
SettingsProperty property = (SettingsProperty)enumerator.Current;
ICollection myKeys = property.Attributes.Keys;
foreach (object theKey in myKeys)
System.Diagnostics.Debug.Print(theKey.ToString());
// One of the keys returned is:
System.Configuration.SettingsDescriptionAttribute
}
enumerator.Reset();
while (enumerator.MoveNext())
{
SettingsProperty property = (SettingsProperty)enumerator.Current;
string propertyValue = property.DefaultValue.ToString();
// This fails: Null Reference
string propertyDescription =
property.Attributes["System.Configuration.SettingsDescriptionAttribute"].ToString();
// Do stuff with strings...
}
}