DictionarySectionHandler.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. public object Create(object parent, object context, XmlNode section)
  38. {
  39. //FIXME: Enter a meaningful error message
  40. if(section == null)
  41. { throw new ConfigurationException("XML Node can not be null."); }
  42. //FIXME: Enter a meaningful error message
  43. if(parent == null)
  44. { throw new ConfigurationException("", section); }
  45. DictionarySectionHandler objHandler = new DictionarySectionHandler();
  46. NameValueCollection objCollection;
  47. //Unbox parent as a NameValueCollection type.
  48. objCollection=(NameValueCollection)parent;
  49. objCollection.Add(section.Attributes[_stringKeyName].Value, section.Attributes[_stringValueName].Value);
  50. return null;
  51. //FIXME: this code is far form complete, probably not even correct.
  52. }
  53. /// <summary>
  54. /// Gets the name of the key attribute tag. This property is overidden by derived classes to change
  55. /// the name of the key attribute tag. The default is "key".
  56. /// </summary>
  57. protected virtual string KeyAttributeName
  58. {
  59. get
  60. {
  61. return _stringKeyName;
  62. }
  63. }
  64. /// <summary>
  65. /// Gets the name of the value tag. This property may be overidden by derived classes to change
  66. /// the name of the value tag. The default is "value".
  67. /// </summary>
  68. protected virtual string ValueAttributeName
  69. {
  70. get
  71. {
  72. return _stringValueName;
  73. }
  74. }
  75. }
  76. }