/// <summary> /// /// </summary> /// <param name="parent"></param> /// <param name="context"></param> /// <param name="section"></param> /// <returns></returns> public virtual object Create(object parent, object context, XmlNode section) { Hashtable result; // Create a shallow clone of the parent if (parent == null) { result = new Hashtable(new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture), new CaseInsensitiveComparer(CultureInfo.InvariantCulture)); } else { result = (Hashtable)((Hashtable)parent).Clone(); } // Process XML HandlerBase.CheckForUnrecognizedAttributes(section); foreach (XmlNode child in section.ChildNodes) { // Skip whitespace and comments; throw exception if non-element if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child)) { continue; } // Handle <add>, <remove>, and <clear> tags if (child.Name == "add") { string key = HandlerBase.RemoveRequiredAttribute(child, KeyAttributeName); string value = HandlerBase.RemoveAttribute(child, ValueAttributeName); HandlerBase.CheckForUnrecognizedAttributes(child); if (value == null) { value = string.Empty; } result[key] = value; } else if (child.Name == "remove") { string key = HandlerBase.RemoveRequiredAttribute(child, KeyAttributeName); HandlerBase.CheckForUnrecognizedAttributes(child); result.Remove(key); } else if (child.Name == "clear") { HandlerBase.CheckForUnrecognizedAttributes(child); result.Clear(); } else { HandlerBase.ThrowUnrecognizedElement(child); } } return(result); }
internal static object CreateStatic(object parent, XmlNode section, string keyAttriuteName, string valueAttributeName) { ReadOnlyNameValueCollection result; if (parent == null) { result = new ReadOnlyNameValueCollection(new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture), new CaseInsensitiveComparer(CultureInfo.InvariantCulture)); } else { result = new ReadOnlyNameValueCollection((ReadOnlyNameValueCollection)parent); } HandlerBase.CheckForUnrecognizedAttributes(section); foreach (XmlNode child in section.ChildNodes) { if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child)) { continue; } if (child.Name == "add") { string key = HandlerBase.RemoveRequiredAttribute(child, keyAttriuteName); string val = HandlerBase.RemoveRequiredAttribute(child, valueAttributeName, true); HandlerBase.CheckForUnrecognizedAttributes(child); result[key] = val; } else if (child.Name == "remove") { string key = HandlerBase.RemoveRequiredAttribute(child, keyAttriuteName); HandlerBase.CheckForUnrecognizedAttributes(child); result.Remove(key); } else if (child.Name.Equals("clear")) { HandlerBase.CheckForUnrecognizedAttributes(child); result.Clear(); } else { HandlerBase.ThrowUnrecognizedElement(child); } } result.SetReadOnly(); return(result); }
/// <summary> /// Returns a collection of configuration section values. /// </summary> /// <param name="parent">The configuration settings in a corresponding parent configuration section.</param> /// <param name="context">This parameter is reserved and is null.</param> /// <param name="section">An <see cref="System.Xml.XmlNode"/> that contains configuration information from the configuration file. /// Provides direct access to the XML contents of the configuration section.</param> /// <returns>A <see cref="Hashtable"/> containing configuration section directives.</returns> public virtual object Create(object parent, object context, XmlNode section) { Hashtable result; // start result off as a shallow clone of the parent if (parent == null) { result = new Hashtable(); } else { result = new Hashtable((Hashtable)parent); } // Check for child nodes HandlerBase.CheckForChildNodes(section); foreach (XmlNode attribute in section.Attributes) { result[attribute.Name] = attribute.Value; } return(result); }