【发布时间】:2016-12-25 19:43:57
【问题描述】:
我需要手动将旧 user.config 与新设置合并,现在我只想将旧值加载到字典中:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<userSettings>
<myprog.Properties.Settings>
<setting name="openkey" serializeAs="String">
<value>o</value>
</setting>
<setting name="licenseAccepted" serializeAs="String">
<value>True</value>
</setting>
代码:
Dictionary<string, string> myDictionary = new Dictionary<string, string>();
XmlDocument document = new XmlDocument();
document.Load(OlderSettingLocation);
XmlNodeList s = document.SelectNodes("/configuration/userSettings/myprog.Properties.Settings/setting");
foreach (XmlNode node in s)
{
myDictionary.Add(node.Attributes["name"].Value, node.Attributes["value"].Value);
}
这导致 node.Attributes["name"].Value 在第一个循环中是“设置”而不是“openkey”,并且值为 null
【问题讨论】:
-
你能给出一个更完整的具有多个设置的示例吗?