Enumerating Settings in .NET Applications

Today I’d like to give you a short example how to simply enumerate all current settings in your .NET application. Fortunately the following C# code snippet works for both application and user settings: :)

1
2
foreach (SettingsProperty sp in Properties.Settings.Default.Properties)
    Console.WriteLine(sp.Name + " = " + Properties.Settings.Default[sp.Name]);

First of all the detection of all property names is quit easy cp. sp.Name. However after this the query of the current property value is a bit tricky ’cause SettingsProperty only provides the attribute DefaultValue. As you remember the DefaultValue is the value you defined in Visual Studio and it can naturally differ if your customer change the config file by hand. So with the sample above properties can be determined at runtime using the property name as an index in Properties.Settings.Default.

0 Responses to “Enumerating Settings in .NET Applications”


  • No Comments

Leave a Reply