Application Settings. How to iterate ?
-
Visual Studio 2008 / C# / windows application I have some application settings and would like to iterate through them so that I can put them into a list. So far I have not been able to find a way. I've tried to use an enumerator
IEnumerator enuEnumerator = Properties.Settings.Default.Properties.GetEnumerator();
while (enuEnumerator.MoveNext())
{
MessageBox.Show(enuEnumerator.Current.ToString());
}but the string is "System.Configuration.SettingsProperty" Also, I cannot use an indexer because a string is required raher than a number...
Properties.Settings.Default.Properties[i]
Does anyone know how to do this? :confused:
-
Visual Studio 2008 / C# / windows application I have some application settings and would like to iterate through them so that I can put them into a list. So far I have not been able to find a way. I've tried to use an enumerator
IEnumerator enuEnumerator = Properties.Settings.Default.Properties.GetEnumerator();
while (enuEnumerator.MoveNext())
{
MessageBox.Show(enuEnumerator.Current.ToString());
}but the string is "System.Configuration.SettingsProperty" Also, I cannot use an indexer because a string is required raher than a number...
Properties.Settings.Default.Properties[i]
Does anyone know how to do this? :confused:
Hi, If you cast the enumerator's Current value to a SettingsProperty then you should get to the information you need. My code essentially does that and shows how to enumerate both the default and current value collections.
internal void ShowSettings() { Console.WriteLine("Default values"); SettingsPropertyCollection spc = Properties.Settings.Default.Properties; foreach (SettingsProperty sp in spc) { Console.WriteLine("{0} '{1}'", sp.Name, sp.DefaultValue); } Console.WriteLine("\\nCurrent values"); SettingsPropertyValueCollection spvc = Properties.Settings.Default.PropertyValues; foreach (SettingsPropertyValue spv in spvc) { Console.WriteLine("{0} '{1}'", spv.Name, spv.PropertyValue); } }
Alan.
-
Visual Studio 2008 / C# / windows application I have some application settings and would like to iterate through them so that I can put them into a list. So far I have not been able to find a way. I've tried to use an enumerator
IEnumerator enuEnumerator = Properties.Settings.Default.Properties.GetEnumerator();
while (enuEnumerator.MoveNext())
{
MessageBox.Show(enuEnumerator.Current.ToString());
}but the string is "System.Configuration.SettingsProperty" Also, I cannot use an indexer because a string is required raher than a number...
Properties.Settings.Default.Properties[i]
Does anyone know how to do this? :confused:
-
Visual Studio 2008 / C# / windows application I have some application settings and would like to iterate through them so that I can put them into a list. So far I have not been able to find a way. I've tried to use an enumerator
IEnumerator enuEnumerator = Properties.Settings.Default.Properties.GetEnumerator();
while (enuEnumerator.MoveNext())
{
MessageBox.Show(enuEnumerator.Current.ToString());
}but the string is "System.Configuration.SettingsProperty" Also, I cannot use an indexer because a string is required raher than a number...
Properties.Settings.Default.Properties[i]
Does anyone know how to do this? :confused:
Thanks both for your prompt responses. Case closed.