For each element in the settings of my application, I added text to my Description Property , which I want to get at runtime. I am sure that there is no basic logical nuance here, but everything I tried failed. Clearly, my understanding of what value needs to be passed to the Attributes attribute of the SettingsProperty class is incorrect. I am even more confused by the fact that when I repeat all the keys returned by SettingsProperty.Attributes.Keys, I can see "System.Configuration.SettingsDescriptionAttribute", but when I pass this string as a key to the attribute property, null returns.
Any understanding of how to get the value of Property Description would be greatly appreciated. Thank you. :)
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... } }
source share