ConfigurationSectionGroupCollection.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // System.Configuration.ConfigurationSectionGroupCollection.cs
  3. //
  4. // Authors:
  5. // Duncan Mak ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining
  9. // a copy of this software and associated documentation files (the
  10. // "Software"), to deal in the Software without restriction, including
  11. // without limitation the rights to use, copy, modify, merge, publish,
  12. // distribute, sublicense, and/or sell copies of the Software, and to
  13. // permit persons to whom the Software is furnished to do so, subject to
  14. // the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be
  17. // included in all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. //
  27. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  28. //
  29. #if NET_2_0 && XML_DEP
  30. using System;
  31. using System.Collections;
  32. using System.Collections.Specialized;
  33. namespace System.Configuration {
  34. public sealed class ConfigurationSectionGroupCollection : NameObjectCollectionBase
  35. {
  36. SectionGroupInfo group;
  37. Configuration config;
  38. internal ConfigurationSectionGroupCollection (Configuration config, SectionGroupInfo group)
  39. {
  40. this.config = config;
  41. this.group = group;
  42. }
  43. public ICollection AllKeys {
  44. get { return group.Groups.AllKeys; }
  45. }
  46. public override int Count {
  47. get { return group.Groups.Count; }
  48. }
  49. public ConfigurationSectionGroup this [string name] {
  50. get {
  51. ConfigurationSectionGroup sec = BaseGet (name) as ConfigurationSectionGroup;
  52. if (sec == null) {
  53. SectionGroupInfo secData = group.Groups [name] as SectionGroupInfo;
  54. if (secData == null) return null;
  55. sec = config.GetSectionGroupInstance (secData);
  56. BaseSet (name, sec);
  57. }
  58. return sec;
  59. }
  60. }
  61. public ConfigurationSectionGroup this [int index] {
  62. get { return this [GetKey (index)]; }
  63. }
  64. public void Add (string name, ConfigurationSectionGroup sectionGroup)
  65. {
  66. config.CreateSectionGroup (group, name, sectionGroup);
  67. }
  68. public void Clear ()
  69. {
  70. if (group.Groups != null) {
  71. foreach (ConfigInfo data in group.Groups)
  72. config.RemoveConfigInfo (data);
  73. }
  74. }
  75. public void CopyTo (ConfigurationSectionGroup [] array, int index)
  76. {
  77. for (int n=0; n<group.Groups.Count; n++)
  78. array [n + index] = this [n];
  79. }
  80. public ConfigurationSectionGroup Get (int index)
  81. {
  82. return this [index];
  83. }
  84. public ConfigurationSectionGroup Get (string name)
  85. {
  86. return this [name];
  87. }
  88. public override IEnumerator GetEnumerator ()
  89. {
  90. return group.Groups.AllKeys.GetEnumerator ();
  91. }
  92. public string GetKey (int index)
  93. {
  94. return group.Groups.GetKey (index);
  95. }
  96. public void Remove (string name)
  97. {
  98. SectionGroupInfo secData = group.Groups [name] as SectionGroupInfo;
  99. if (secData != null)
  100. config.RemoveConfigInfo (secData);
  101. }
  102. public void RemoveAt (int index)
  103. {
  104. SectionGroupInfo secData = group.Groups [index] as SectionGroupInfo;
  105. config.RemoveConfigInfo (secData);
  106. }
  107. }
  108. }
  109. #endif