ModulesConfiguration.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // System.Web.Configuration.ModulesConfiguration
  3. //
  4. // Authors:
  5. // Patrik Torstensson ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. //
  8. // (c) 2002 Ximian, Inc. (http://www.ximian.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Collections;
  32. namespace System.Web.Configuration
  33. {
  34. class ModulesConfiguration
  35. {
  36. ArrayList modules;
  37. public ModulesConfiguration () : this (null)
  38. {
  39. }
  40. public ModulesConfiguration (ModulesConfiguration parent)
  41. {
  42. if (parent != null)
  43. modules = new ArrayList (parent.modules);
  44. else
  45. modules = new ArrayList ();
  46. }
  47. public void Add (ModuleItem item)
  48. {
  49. modules.Add (item);
  50. }
  51. public ModuleItem Remove (string name)
  52. {
  53. int i = GetIndex (name);
  54. if (i == -1)
  55. return null;
  56. ModuleItem item = (ModuleItem) modules [i];
  57. modules.RemoveAt (i);
  58. return item;
  59. }
  60. public void Clear ()
  61. {
  62. modules.Clear ();
  63. }
  64. public HttpModuleCollection CreateCollection ()
  65. {
  66. HttpModuleCollection items = new HttpModuleCollection ();
  67. foreach (ModuleItem item in modules)
  68. items.AddModule (item.ModuleName, item.Create ());
  69. return items;
  70. }
  71. int GetIndex (string name)
  72. {
  73. int end = modules.Count;
  74. for (int i = 0; i < end; i++) {
  75. ModuleItem item = (ModuleItem) modules [i];
  76. if (item.IsMatch (name))
  77. return i;
  78. }
  79. return -1;
  80. }
  81. }
  82. }