CodeNamespaceImportCollection.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // System.CodeDom CodeNamespaceImportCollection Class implementation
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. // Daniel Stodden ([email protected])
  7. //
  8. // (C) 2001 Ximian, Inc.
  9. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  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.Runtime.InteropServices;
  31. using System.Collections;
  32. namespace System.CodeDom
  33. {
  34. /*
  35. * Should probably be derived from CollectionBase like any
  36. * other System.CodeDom.*Collection. MS docs say it currently
  37. * is not, for whichever reason.
  38. */
  39. [Serializable]
  40. [ClassInterface(ClassInterfaceType.AutoDispatch)]
  41. [ComVisible(true)]
  42. public class CodeNamespaceImportCollection
  43. : IList, ICollection, IEnumerable
  44. {
  45. private ArrayList namespaceImports;
  46. //
  47. // Constructors
  48. //
  49. public CodeNamespaceImportCollection ()
  50. {
  51. namespaceImports = new ArrayList();
  52. }
  53. //
  54. // Properties
  55. //
  56. int ICollection.Count {
  57. get {
  58. return namespaceImports.Count;
  59. }
  60. }
  61. public int Count {
  62. get {
  63. return namespaceImports.Count;
  64. }
  65. }
  66. public CodeNamespaceImport this [int index] {
  67. get {
  68. return (CodeNamespaceImport)namespaceImports[index];
  69. }
  70. set {
  71. namespaceImports[index] = value;
  72. }
  73. }
  74. //
  75. // Methods
  76. //
  77. public void Add (CodeNamespaceImport value)
  78. {
  79. if (value == null) {
  80. throw new NullReferenceException ();
  81. }
  82. // perform case-insensitive check to see if the namespace of the
  83. // entry to add is not already in the collection
  84. foreach (CodeNamespaceImport import in this) {
  85. if (string.Compare(import.Namespace, value.Namespace, true) == 0) {
  86. // skip duplicate namespaces
  87. return;
  88. }
  89. }
  90. namespaceImports.Add (value);
  91. }
  92. public void AddRange (CodeNamespaceImport [] value)
  93. {
  94. if (value == null) {
  95. throw new ArgumentNullException ("value");
  96. }
  97. foreach (CodeNamespaceImport elem in value) {
  98. Add (elem);
  99. }
  100. }
  101. void IList.Clear ()
  102. {
  103. namespaceImports.Clear ();
  104. }
  105. public void Clear ()
  106. {
  107. namespaceImports.Clear ();
  108. }
  109. // IList implementation
  110. bool IList.IsFixedSize {
  111. get {
  112. return false;
  113. }
  114. }
  115. bool IList.IsReadOnly {
  116. get {
  117. return false;
  118. }
  119. }
  120. object IList.this[int index] {
  121. get {
  122. return namespaceImports[index];
  123. }
  124. set {
  125. namespaceImports[index] = value;
  126. }
  127. }
  128. int IList.Add( object value )
  129. {
  130. return namespaceImports.Add( value );
  131. }
  132. bool IList.Contains( object value )
  133. {
  134. return namespaceImports.Contains( value );
  135. }
  136. int IList.IndexOf( object value )
  137. {
  138. return namespaceImports.IndexOf( value );
  139. }
  140. void IList.Insert( int index, object value )
  141. {
  142. namespaceImports.Insert( index, value );
  143. }
  144. void IList.Remove( object value )
  145. {
  146. namespaceImports.Remove( value );
  147. }
  148. void IList.RemoveAt( int index )
  149. {
  150. namespaceImports.RemoveAt( index );
  151. }
  152. // ICollection implementation
  153. object ICollection.SyncRoot {
  154. get {
  155. return null;
  156. }
  157. }
  158. bool ICollection.IsSynchronized {
  159. get {
  160. return namespaceImports.IsSynchronized;
  161. }
  162. }
  163. void ICollection.CopyTo( Array array, int index )
  164. {
  165. namespaceImports.CopyTo( array, index );
  166. }
  167. // IEnumerable implementation
  168. IEnumerator IEnumerable.GetEnumerator ()
  169. {
  170. return namespaceImports.GetEnumerator();
  171. }
  172. // IEnumerable implementation
  173. public IEnumerator GetEnumerator ()
  174. {
  175. return namespaceImports.GetEnumerator();
  176. }
  177. }
  178. }