DictionarySectionHandler.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // System.Configuration.DictionarySectionHandler.cs
  3. //
  4. // Author:
  5. // Christopher Podurgiel ([email protected])
  6. //
  7. // (C) Chris Podurgiel
  8. //
  9. using System;
  10. using System.Collections.Specialized;
  11. using System.Xml;
  12. namespace System.Configuration
  13. {
  14. /// <summary>
  15. /// Summary description for DictionarySectionHandler.
  16. /// </summary>
  17. public class DictionarySectionHandler : IConfigurationSectionHandler
  18. {
  19. private static string _stringKeyName;
  20. private static string _stringValueName;
  21. /// <summary>
  22. /// DictionarySectionHandler Constructor
  23. /// </summary>
  24. public DictionarySectionHandler()
  25. {
  26. //Set Default Values.
  27. _stringKeyName = "key";
  28. _stringValueName = "value";
  29. }
  30. /// <summary>
  31. /// Creates a new DictionarySectionHandler object and adds the object to the collection.
  32. /// </summary>
  33. /// <param name="parent">Composed from the configuration settings in a corresponding parent configuration section.</param>
  34. /// <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>
  35. /// <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>
  36. /// <returns></returns>
  37. [MonoTODO]
  38. public virtual object Create(object parent, object context, XmlNode section)
  39. {
  40. //FIXME: Enter a meaningful error message
  41. if(section == null)
  42. { throw new ConfigurationException("XML Node can not be null."); }
  43. //FIXME: Enter a meaningful error message
  44. if(parent == null)
  45. { throw new ConfigurationException("", section); }
  46. DictionarySectionHandler objHandler = new DictionarySectionHandler();
  47. NameValueCollection objCollection;
  48. //Unbox parent as a NameValueCollection type.
  49. objCollection=(NameValueCollection)parent;
  50. objCollection.Add(section.Attributes[_stringKeyName].Value, section.Attributes[_stringValueName].Value);
  51. return null;
  52. //FIXME: this code is far form complete, probably not even correct.
  53. }
  54. /// <summary>
  55. /// Gets the name of the key attribute tag. This property is overidden by derived classes to change
  56. /// the name of the key attribute tag. The default is "key".
  57. /// </summary>
  58. protected virtual string KeyAttributeName
  59. {
  60. get
  61. {
  62. return _stringKeyName;
  63. }
  64. }
  65. /// <summary>
  66. /// Gets the name of the value tag. This property may be overidden by derived classes to change
  67. /// the name of the value tag. The default is "value".
  68. /// </summary>
  69. protected virtual string ValueAttributeName
  70. {
  71. get
  72. {
  73. return _stringValueName;
  74. }
  75. }
  76. }
  77. }