Permalink
Browse files

store settings in a setting node rather than a node named after the s…

…etting's name (cleaner)
1 parent 3a3e80b commit 95dd2266147309aa4095fdd0e276b40a8747c802 @crdx committed Oct 23, 2012
Showing with 10 additions and 11 deletions.
  1. +10 −11 src/PortableSettingsProvider.cs
@@ -137,21 +137,28 @@ private void SetValue(SettingsPropertyValue propertyValue)
? _globalSettingsNode
: _localSettingsNode;
- XmlNode settingNode = targetNode.SelectSingleNode(propertyValue.Name);
+ XmlNode settingNode = targetNode.SelectSingleNode(string.Format("setting[@name='{0}']", propertyValue.Name));
if (settingNode != null)
settingNode.InnerText = propertyValue.SerializedValue.ToString();
else
{
- settingNode = CreateTextElement(propertyValue.Name, propertyValue.SerializedValue.ToString());
+ settingNode = _rootDocument.CreateElement("setting");
+
+ XmlAttribute nameAttribute = _rootDocument.CreateAttribute("name");
+ nameAttribute.Value = propertyValue.Name;
+
+ settingNode.Attributes.Append(nameAttribute);
+ settingNode.InnerText = propertyValue.SerializedValue.ToString();
+
targetNode.AppendChild(settingNode);
}
}
private string GetValue(SettingsProperty property)
{
XmlNode targetNode = IsGlobal(property) ? _globalSettingsNode : _localSettingsNode;
- XmlNode settingNode = targetNode.SelectSingleNode(property.Name);
+ XmlNode settingNode = targetNode.SelectSingleNode(string.Format("setting[@name='{0}']", property.Name));
if (settingNode == null)
return property.DefaultValue != null ? property.DefaultValue.ToString() : string.Empty;
@@ -170,14 +177,6 @@ private bool IsGlobal(SettingsProperty property)
return false;
}
- private XmlNode CreateTextElement(string name, string innerText)
- {
- XmlNode xmlElement = _rootDocument.CreateElement(name);
- xmlElement.InnerText = innerText;
-
- return xmlElement;
- }
-
private XmlNode GetSettingsNode(string name)
{
XmlNode settingsNode = _rootNode.SelectSingleNode(name);

0 comments on commit 95dd226

Please sign in to comment.