/// <summary></summary> /// <param name="list"></param> /// <param name="node"></param> public static void SetKeyValues(NameValueConfigurationCollection list, YamlMappingNode node) { if (list == null) { throw new ArgumentNullException("list"); } foreach (var entry in node.Children) { bool isExist = false; NameValueConfigurationElement nameValue = new NameValueConfigurationElement(entry.Key.ToString(), entry.Value.ToString()); string[] keys = list.AllKeys; foreach (string key in keys) { if (nameValue.Name == key) { list[nameValue.Name].Value = nameValue.Value; isExist = true; break; } } if (!isExist) { list.Add(nameValue); } } }
/// <summary></summary> /// <param name="list"></param> /// <param name="nodes"></param> public static void SetKeyValues(NameValueConfigurationCollection list, XmlNodeList nodes) { if (list == null) { throw new ArgumentNullException("list"); } foreach (XmlNode node in nodes) { bool isExist = false; NameValueConfigurationElement nameValue = new NameValueConfigurationElement(node.Attributes["name"].Value, node.Attributes["value"].Value); string[] keys = list.AllKeys; foreach (string key in keys) { if (nameValue.Name == key) { list[nameValue.Name].Value = nameValue.Value; isExist = true; break; } } if (!isExist) { list.Add(nameValue); } } }