【发布时间】:2015-10-11 00:28:54
【问题描述】:
我目前正在处理一个 VSTO 项目,我有 5 个 .settings 文件:
-
Settings.settings(默认) -
s201213.settings -
s201314.settings -
s201415.settings -
s201516.settings
随着时间的推移,将包含更多遵循相同命名约定的设置文件('s' 后跟纳税年度)。
我知道我可以遍历设置文件,但有没有办法遍历实际设置文件本身?
我尝试过以下方法:
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());
}
}
这显然只遍历单个设置文件,但我似乎无法弄清楚将所有设置文件作为一个集合进行迭代的逻辑,而无需在代码中明确命名每个设置文件。我希望这是有道理的,任何帮助表示赞赏。
更新:
我想我正在使用以下代码到达某个地方:
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);
}
}
}
这似乎是在识别设置文件和存储的值:
输出:
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
但是我似乎无法获得应该返回Double 的“LEL”设置的实际值?
第二次更新
我实际上已经放弃并决定改用本地数据库-但我仍然想知道这是否可能,而且我认为其他人也想知道,所以我将悬赏尝试并产生一些兴趣。
【问题讨论】:
标签: c# settings application-settings