I am currently working on a VSTO project for which I have 5 .settingsfiles:
Settings.settings (default)s201213.settingss201314.settingss201415.settingss201516.settings
Over time, more settings files will be added after the same naming convention ('s' followed by the tax year).
I know that I can iterate through the settings file, but is there a way to iterate over the settings files themselves?
I tried things like:
public void Example()
{
System.Collections.IEnumerator testSetting = MyAddIn.Properties.s201213.Default.Properties.GetEnumerator();
while (testSetting.MoveNext())
{
System.Diagnostics.Debug.WriteLine("Setting:\t" + testSetting.Current.ToString());
}
}
Which, obviously, only iterates through one settings file, but I can’t understand the logic of repeating all settings files as a collection without explicitly naming each of them in the code. Hope this makes sense, any help is appreciated.
Update:
I think I'm getting code with the following code:
foreach(Type test in Assembly.GetExecutingAssembly().GetTypes())
{
if (System.Text.RegularExpressions.Regex.IsMatch(test.Name, "^s[0-9]{6}$"))
{
PropertyInfo value = test.GetProperty("LEL");
try
{
System.Diagnostics.Debug.WriteLine("Name:\t" + test.Name +
"\nNameSpace:\t" + test.Namespace +
"\nProperty:\t" + test.GetProperty("LEL").ToString() +
"\n");
}
catch(Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
}
}
It seems to recognize the settings files and stored values:
Output:
Name: s201213
NameSpace: MyAddIn.Properties
Property: Double LEL
Name: s201314
NameSpace: MyAddIn.Properties
Property: Double LEL
Name: s201415
NameSpace: MyAddIn.Properties
Property: Double LEL
Name: s201516
NameSpace: MyAddIn.Properties
Property: Double LEL
, , "LEL", Double?
, , , , , , .