PageRenderTime 276ms CodeModel.GetById 17ms RepoModel.GetById 2ms app.codeStats 1ms

/IDE/ICSharpCode.TextEditor/Document/Selection/SelectionCollection.cs

https://bitbucket.org/AdamMil/boaold
C# | 266 lines | 103 code | 26 blank | 137 comment | 2 complexity | 932000d4ff19f926c33456c2b7b4aabc MD5 | raw file
Possible License(s): GPL-2.0
  1. // <file>
  2. // <copyright see="prj:///doc/copyright.txt"/>
  3. // <license see="prj:///doc/license.txt"/>
  4. // <owner name="Mike KrĂźger" email="mike@icsharpcode.net"/>
  5. // <version value="$version"/>
  6. // </file>
  7. using System;
  8. using System.Collections;
  9. namespace ICSharpCode.TextEditor.Document
  10. {
  11. /// <summary>
  12. /// <para>
  13. /// A collection that stores <see cref='ISelection'/> objects.
  14. /// </para>
  15. /// </summary>
  16. /// <seealso cref='SelectionCollection'/>
  17. [Serializable()]
  18. public class SelectionCollection : CollectionBase {
  19. /// <summary>
  20. /// <para>
  21. /// Initializes a new instance of <see cref='SelectionCollection'/>.
  22. /// </para>
  23. /// </summary>
  24. public SelectionCollection()
  25. {
  26. }
  27. /// <summary>
  28. /// <para>
  29. /// Initializes a new instance of <see cref='SelectionCollection'/> based on another <see cref='SelectionCollection'/>.
  30. /// </para>
  31. /// </summary>
  32. /// <param name='value'>
  33. /// A <see cref='SelectionCollection'/> from which the contents are copied
  34. /// </param>
  35. public SelectionCollection(SelectionCollection value)
  36. {
  37. this.AddRange(value);
  38. }
  39. /// <summary>
  40. /// <para>
  41. /// Initializes a new instance of <see cref='SelectionCollection'/> containing any array of <see cref='ISelection'/> objects.
  42. /// </para>
  43. /// </summary>
  44. /// <param name='value'>
  45. /// A array of <see cref='ISelection'/> objects with which to intialize the collection
  46. /// </param>
  47. public SelectionCollection(ISelection[] value)
  48. {
  49. this.AddRange(value);
  50. }
  51. /// <summary>
  52. /// <para>Represents the entry at the specified index of the <see cref='ISelection'/>.</para>
  53. /// </summary>
  54. /// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>
  55. /// <value>
  56. /// <para> The entry at the specified index of the collection.</para>
  57. /// </value>
  58. /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
  59. public ISelection this[int index]
  60. {
  61. get {
  62. return ((ISelection)(List[index]));
  63. }
  64. set {
  65. List[index] = value;
  66. }
  67. }
  68. /// <summary>
  69. /// <para>Adds a <see cref='ISelection'/> with the specified value to the
  70. /// <see cref='SelectionCollection'/> .</para>
  71. /// </summary>
  72. /// <param name='value'>The <see cref='ISelection'/> to add.</param>
  73. /// <returns>
  74. /// <para>The index at which the new element was inserted.</para>
  75. /// </returns>
  76. /// <seealso cref='SelectionCollection.AddRange'/>
  77. public int Add(ISelection value)
  78. {
  79. return List.Add(value);
  80. }
  81. /// <summary>
  82. /// <para>Copies the elements of an array to the end of the <see cref='SelectionCollection'/>.</para>
  83. /// </summary>
  84. /// <param name='value'>
  85. /// An array of type <see cref='ISelection'/> containing the objects to add to the collection.
  86. /// </param>
  87. /// <returns>
  88. /// <para>None.</para>
  89. /// </returns>
  90. /// <seealso cref='SelectionCollection.Add'/>
  91. public void AddRange(ISelection[] value)
  92. {
  93. for (int i = 0; (i < value.Length); i = (i + 1)) {
  94. this.Add(value[i]);
  95. }
  96. }
  97. /// <summary>
  98. /// <para>
  99. /// Adds the contents of another <see cref='SelectionCollection'/> to the end of the collection.
  100. /// </para>
  101. /// </summary>
  102. /// <param name='value'>
  103. /// A <see cref='SelectionCollection'/> containing the objects to add to the collection.
  104. /// </param>
  105. /// <returns>
  106. /// <para>None.</para>
  107. /// </returns>
  108. /// <seealso cref='SelectionCollection.Add'/>
  109. public void AddRange(SelectionCollection value)
  110. {
  111. for (int i = 0; (i < value.Count); i = (i + 1)) {
  112. this.Add(value[i]);
  113. }
  114. }
  115. /// <summary>
  116. /// <para>Gets a value indicating whether the
  117. /// <see cref='SelectionCollection'/> contains the specified <see cref='ISelection'/>.</para>
  118. /// </summary>
  119. /// <param name='value'>The <see cref='ISelection'/> to locate.</param>
  120. /// <returns>
  121. /// <para><see langword='true'/> if the <see cref='ISelection'/> is contained in the collection;
  122. /// otherwise, <see langword='false'/>.</para>
  123. /// </returns>
  124. /// <seealso cref='SelectionCollection.IndexOf'/>
  125. public bool Contains(ISelection value)
  126. {
  127. return List.Contains(value);
  128. }
  129. /// <summary>
  130. /// <para>Copies the <see cref='SelectionCollection'/> values to a one-dimensional <see cref='System.Array'/> instance at the
  131. /// specified index.</para>
  132. /// </summary>
  133. /// <param name='array'><para>The one-dimensional <see cref='System.Array'/> that is the destination of the values copied from <see cref='SelectionCollection'/> .</para></param>
  134. /// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
  135. /// <returns>
  136. /// <para>None.</para>
  137. /// </returns>
  138. /// <exception cref='System.ArgumentException'><para><paramref name='array'/> is multidimensional.</para> <para>-or-</para> <para>The number of elements in the <see cref='SelectionCollection'/> is greater than the available space between <paramref name='arrayIndex'/> and the end of <paramref name='array'/>.</para></exception>
  139. /// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
  140. /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
  141. /// <seealso cref='System.Array'/>
  142. public void CopyTo(ISelection[] array, int index)
  143. {
  144. List.CopyTo(array, index);
  145. }
  146. /// <summary>
  147. /// <para>Returns the index of a <see cref='ISelection'/> in
  148. /// the <see cref='SelectionCollection'/> .</para>
  149. /// </summary>
  150. /// <param name='value'>The <see cref='ISelection'/> to locate.</param>
  151. /// <returns>
  152. /// <para>The index of the <see cref='ISelection'/> of <paramref name='value'/> in the
  153. /// <see cref='SelectionCollection'/>, if found; otherwise, -1.</para>
  154. /// </returns>
  155. /// <seealso cref='SelectionCollection.Contains'/>
  156. public int IndexOf(ISelection value)
  157. {
  158. return List.IndexOf(value);
  159. }
  160. /// <summary>
  161. /// <para>Inserts a <see cref='ISelection'/> into the <see cref='SelectionCollection'/> at the specified index.</para>
  162. /// </summary>
  163. /// <param name='index'>The zero-based index where <paramref name='value'/> should be inserted.</param>
  164. /// <param name=' value'>The <see cref='ISelection'/> to insert.</param>
  165. /// <returns><para>None.</para></returns>
  166. /// <seealso cref='SelectionCollection.Add'/>
  167. public void Insert(int index, ISelection value)
  168. {
  169. List.Insert(index, value);
  170. }
  171. /// <summary>
  172. /// <para>Returns an enumerator that can iterate through
  173. /// the <see cref='SelectionCollection'/> .</para>
  174. /// </summary>
  175. /// <returns><para>None.</para></returns>
  176. /// <seealso cref='System.Collections.IEnumerator'/>
  177. public new ISelectionEnumerator GetEnumerator()
  178. {
  179. return new ISelectionEnumerator(this);
  180. }
  181. /// <summary>
  182. /// <para> Removes a specific <see cref='ISelection'/> from the
  183. /// <see cref='SelectionCollection'/> .</para>
  184. /// </summary>
  185. /// <param name='value'>The <see cref='ISelection'/> to remove from the <see cref='SelectionCollection'/> .</param>
  186. /// <returns><para>None.</para></returns>
  187. /// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception>
  188. public void Remove(ISelection value)
  189. {
  190. List.Remove(value);
  191. }
  192. /// <summary>
  193. /// used internally
  194. /// </summary>
  195. public class ISelectionEnumerator : object, IEnumerator {
  196. private IEnumerator baseEnumerator;
  197. private IEnumerable temp;
  198. /// <summary>
  199. /// Creates a new instance of <see cref="ISelectionEnumerator"/>
  200. /// </summary>
  201. public ISelectionEnumerator(SelectionCollection mappings)
  202. {
  203. this.temp = ((IEnumerable)(mappings));
  204. this.baseEnumerator = temp.GetEnumerator();
  205. }
  206. /// <remarks>
  207. /// </remarks>
  208. public ISelection Current {
  209. get {
  210. return ((ISelection)(baseEnumerator.Current));
  211. }
  212. }
  213. object IEnumerator.Current {
  214. get {
  215. return baseEnumerator.Current;
  216. }
  217. }
  218. /// <remarks>
  219. /// </remarks>
  220. public bool MoveNext()
  221. {
  222. return baseEnumerator.MoveNext();
  223. }
  224. bool IEnumerator.MoveNext()
  225. {
  226. return baseEnumerator.MoveNext();
  227. }
  228. /// <remarks>
  229. /// </remarks>
  230. public void Reset()
  231. {
  232. baseEnumerator.Reset();
  233. }
  234. void IEnumerator.Reset()
  235. {
  236. baseEnumerator.Reset();
  237. }
  238. }
  239. }
  240. }