WebRequestModuleHandler.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // System.Net.Configuration.WebRequestModuleHandler
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2003 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System.Collections;
  10. using System.Configuration;
  11. using System.Xml;
  12. namespace System.Net.Configuration
  13. {
  14. class WebRequestModuleHandler : IConfigurationSectionHandler
  15. {
  16. public virtual object Create (object parent, object configContext, XmlNode section)
  17. {
  18. if (section.Attributes != null && section.Attributes.Count != 0)
  19. HandlersUtil.ThrowException ("Unrecognized attribute", section);
  20. XmlNodeList reqHandlers = section.ChildNodes;
  21. foreach (XmlNode child in reqHandlers) {
  22. XmlNodeType ntype = child.NodeType;
  23. if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
  24. continue;
  25. if (ntype != XmlNodeType.Element)
  26. HandlersUtil.ThrowException ("Only elements allowed", child);
  27. string name = child.Name;
  28. if (name == "clear") {
  29. if (child.Attributes != null && child.Attributes.Count != 0)
  30. HandlersUtil.ThrowException ("Unrecognized attribute", child);
  31. WebRequest.ClearPrefixes ();
  32. continue;
  33. }
  34. string prefix = HandlersUtil.ExtractAttributeValue ("prefix", child);
  35. if (name == "add") {
  36. string type = HandlersUtil.ExtractAttributeValue ("type", child, false);
  37. if (child.Attributes != null && child.Attributes.Count != 0)
  38. HandlersUtil.ThrowException ("Unrecognized attribute", child);
  39. WebRequest.AddPrefix (prefix, type);
  40. continue;
  41. }
  42. if (name == "remove") {
  43. if (child.Attributes != null && child.Attributes.Count != 0)
  44. HandlersUtil.ThrowException ("Unrecognized attribute", child);
  45. WebRequest.RemovePrefix (prefix);
  46. continue;
  47. }
  48. HandlersUtil.ThrowException ("Unexpected element", child);
  49. }
  50. return null;
  51. }
  52. }
  53. }