CodeNamespaceImportCollection.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. public int Count {
  57. get {
  58. return namespaceImports.Count;
  59. }
  60. }
  61. public CodeNamespaceImport this [int index] {
  62. get {
  63. return (CodeNamespaceImport)namespaceImports[index];
  64. }
  65. set {
  66. namespaceImports[index] = value;
  67. }
  68. }
  69. //
  70. // Methods
  71. //
  72. public void Add (CodeNamespaceImport value)
  73. {
  74. if (value == null) {
  75. throw new NullReferenceException ();
  76. }
  77. // perform case-insensitive check to see if the namespace of the
  78. // entry to add is not already in the collection
  79. foreach (CodeNamespaceImport import in this) {
  80. if (string.Compare(import.Namespace, value.Namespace, true) == 0) {
  81. // skip duplicate namespaces
  82. return;
  83. }
  84. }
  85. namespaceImports.Add (value);
  86. }
  87. public void AddRange (CodeNamespaceImport [] value)
  88. {
  89. if (value == null) {
  90. throw new ArgumentNullException ("value");
  91. }
  92. foreach (CodeNamespaceImport elem in value) {
  93. Add (elem);
  94. }
  95. }
  96. public void Clear ()
  97. {
  98. namespaceImports.Clear ();
  99. }
  100. // IList implementation
  101. bool IList.IsFixedSize {
  102. get {
  103. return false;
  104. }
  105. }
  106. bool IList.IsReadOnly {
  107. get {
  108. return false;
  109. }
  110. }
  111. object IList.this[int index] {
  112. get {
  113. return namespaceImports[index];
  114. }
  115. set {
  116. namespaceImports[index] = value;
  117. }
  118. }
  119. int IList.Add( object value )
  120. {
  121. return namespaceImports.Add( value );
  122. }
  123. bool IList.Contains( object value )
  124. {
  125. return namespaceImports.Contains( value );
  126. }
  127. int IList.IndexOf( object value )
  128. {
  129. return namespaceImports.IndexOf( value );
  130. }
  131. void IList.Insert( int index, object value )
  132. {
  133. namespaceImports.Insert( index, value );
  134. }
  135. void IList.Remove( object value )
  136. {
  137. namespaceImports.Remove( value );
  138. }
  139. void IList.RemoveAt( int index )
  140. {
  141. namespaceImports.RemoveAt( index );
  142. }
  143. // ICollection implementation
  144. object ICollection.SyncRoot {
  145. get {
  146. return null;
  147. }
  148. }
  149. bool ICollection.IsSynchronized {
  150. get {
  151. return namespaceImports.IsSynchronized;
  152. }
  153. }
  154. void ICollection.CopyTo( Array array, int index )
  155. {
  156. namespaceImports.CopyTo( array, index );
  157. }
  158. // IEnumerable implementation
  159. public IEnumerator GetEnumerator ()
  160. {
  161. return namespaceImports.GetEnumerator();
  162. }
  163. }
  164. }