2 // System.Configuration.NameValueSectionHandler.cs
5 // Christopher Podurgiel (cpodurgiel@msn.com)
11 using System.Collections.Specialized;
13 namespace System.Configuration
16 /// Summary description for NameValueSectionHandler.
18 public class NameValueSectionHandler
20 private static string keyName;
21 private static string valueName;
22 private static NameValueCollection settingsCollection;
26 /// NameValueSectionHandler Constructor
28 public NameValueSectionHandler()
34 settingsCollection = new NameValueCollection();
39 /// Creates a new configuration handler and adds the specified configuration object to the collection.
41 /// <param name="parent">Composed from the configuration settings in a corresponding parent configuration section.</param>
42 /// <param name="context">Provides access to the virtual path for which the configuration section handler computes configuration values. Normally this parameter is reserved and is null.</param>
43 /// <param name="section">The XML node that contains the configuration information to be handled. section provides direct access to the XML contents of the configuration section.</param>
44 /// <returns></returns>
46 public object Create(object parent, object context, XmlNode section)
48 //FIXME: I'm not quite sure how to implement 'parent' or 'context'.
51 //Get all of the ChildNodes in the XML section.
52 XmlNodeList childNodeList = section.ChildNodes;
54 //loop throught the ChildNodes
55 for (int i=0; i < childNodeList.Count; i++)
57 XmlNode childNode = childNodeList[i];
59 //if the name of this childNode is not 'add' then throw a ConfigurationException.
60 if(childNode.Name != "add")
62 throw (new ConfigurationException("Unrecognized element"));
65 //Get the attributes for the childNode
66 XmlAttributeCollection xmlAttributes = childNode.Attributes;
68 //Get the key and value Attributes by their Name
69 XmlAttribute keyAttribute = xmlAttributes[keyName];
70 XmlAttribute valueAttribute = xmlAttributes[valueName];
72 //Add this Key/Value Pair to the collection
73 settingsCollection.Add(keyAttribute.Value, valueAttribute.Value);
78 //FIXME: Something is missing here. MS's version of this method returns a System.Configuration.ReadOnlyNameValueCollection type,
79 //this class id not documented ANYWHERE. This method is curretly returning a NameValueCollection, but it should be ReadOnly.
81 return settingsCollection;
85 /// Gets the name of the key in the key-value pair.
87 protected virtual string KeyAttributeName
96 /// Gets the value for the key in the key-value pair.
98 protected virtual string ValueAttributeName