SchemaImporterExtensionElementCollection.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // SchemaImporterExtensionElementCollection.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc.
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0 && CONFIGURATION_DEP
  30. using System;
  31. using System.Collections;
  32. using System.Configuration;
  33. using System.Globalization;
  34. using System.Xml;
  35. using System.Text;
  36. namespace System.Xml.Serialization.Configuration
  37. {
  38. [ConfigurationCollection (typeof (SchemaImporterExtensionElement), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
  39. public sealed class SchemaImporterExtensionElementCollection : ConfigurationElementCollection
  40. {
  41. public SchemaImporterExtensionElement this [int index] {
  42. get {
  43. int i = 0;
  44. if (index >= this.Count || index < 0)
  45. throw new ArgumentOutOfRangeException ("index is less than 0 or greater than the count of the collection.");
  46. foreach (SchemaImporterExtensionElement e in this)
  47. if (i++ == index)
  48. return e;
  49. return null; // should not happen
  50. }
  51. set {
  52. if (index >= this.Count || index < 0)
  53. throw new ArgumentOutOfRangeException ("index is less than 0 or greater than the count of the collection.");
  54. RemoveAt (index);
  55. BaseAdd (index, value);
  56. }
  57. }
  58. public new SchemaImporterExtensionElement this [string name] {
  59. get {
  60. foreach (SchemaImporterExtensionElement e in this)
  61. if (e.Name == name)
  62. return e;
  63. return null;
  64. }
  65. set {
  66. Remove (name);
  67. Add (value);
  68. }
  69. }
  70. protected override ConfigurationElement CreateNewElement ()
  71. {
  72. return new SchemaImporterExtensionElement ();
  73. }
  74. protected override object GetElementKey (ConfigurationElement element)
  75. {
  76. return ((SchemaImporterExtensionElement) element).Name;
  77. }
  78. public void Add (SchemaImporterExtensionElement element)
  79. {
  80. BaseAdd (element);
  81. }
  82. public void Clear ()
  83. {
  84. BaseClear ();
  85. }
  86. public int IndexOf (SchemaImporterExtensionElement element)
  87. {
  88. int i = 0;
  89. foreach (SchemaImporterExtensionElement e in this) {
  90. if (element.Equals (e))
  91. return i;
  92. i++;
  93. }
  94. return -1;
  95. }
  96. public void Remove (string name)
  97. {
  98. foreach (SchemaImporterExtensionElement el in this)
  99. if (name == el.Name) {
  100. BaseRemove (el);
  101. break;
  102. }
  103. }
  104. public void Remove (SchemaImporterExtensionElement element)
  105. {
  106. foreach (SchemaImporterExtensionElement el in this)
  107. if (element.Name == el.Name) {
  108. BaseRemove (el);
  109. break;
  110. }
  111. }
  112. public void RemoveAt (int i)
  113. {
  114. BaseRemoveAt (i);
  115. }
  116. }
  117. }
  118. #endif