2
// MonoDevelop XML Editor
4
// Copyright (C) 2005-2006 Matthew Ward
7
using MonoDevelop.Projects.Gui.Completion;
9
using System.Collections;
11
namespace MonoDevelop.XmlEditor.Completion
14
/// A collection that stores <see cref='XmlCompletionData'/> objects.
17
public class XmlCompletionDataCollection : CollectionBase {
20
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/>.
22
public XmlCompletionDataCollection()
27
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/> based on another <see cref='XmlCompletionDataCollection'/>.
29
/// <param name='val'>
30
/// A <see cref='XmlCompletionDataCollection'/> from which the contents are copied
32
public XmlCompletionDataCollection(XmlCompletionDataCollection val)
38
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/> containing any array of <see cref='XmlCompletionData'/> objects.
40
/// <param name='val'>
41
/// A array of <see cref='XmlCompletionData'/> objects with which to intialize the collection
43
public XmlCompletionDataCollection(XmlCompletionData[] val)
49
/// Represents the entry at the specified index of the <see cref='XmlCompletionData'/>.
51
/// <param name='index'>The zero-based index of the entry to locate in the collection.</param>
52
/// <value>The entry at the specified index of the collection.</value>
53
/// <exception cref='ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
54
public XmlCompletionData this[int index] {
56
return ((XmlCompletionData)(List[index]));
64
/// Adds a <see cref='XmlCompletionData'/> with the specified value to the
65
/// <see cref='XmlCompletionDataCollection'/>.
68
/// If the completion data already exists in the collection it is not added.
70
/// <param name='val'>The <see cref='XmlCompletionData'/> to add.</param>
71
/// <returns>The index at which the new element was inserted.</returns>
72
/// <seealso cref='XmlCompletionDataCollection.AddRange'/>
73
public int Add(XmlCompletionData val)
77
index = List.Add(val);
83
/// Copies the elements of an array to the end of the <see cref='XmlCompletionDataCollection'/>.
85
/// <param name='val'>
86
/// An array of type <see cref='XmlCompletionData'/> containing the objects to add to the collection.
88
/// <seealso cref='XmlCompletionDataCollection.Add'/>
89
public void AddRange(XmlCompletionData[] val)
91
for (int i = 0; i < val.Length; i++) {
97
/// Adds the contents of another <see cref='XmlCompletionDataCollection'/> to the end of the collection.
99
/// <param name='val'>
100
/// A <see cref='XmlCompletionDataCollection'/> containing the objects to add to the collection.
102
/// <seealso cref='XmlCompletionDataCollection.Add'/>
103
public void AddRange(XmlCompletionDataCollection val)
105
for (int i = 0; i < val.Count; i++)
112
/// Gets a value indicating whether the
113
/// <see cref='XmlCompletionDataCollection'/> contains the specified <see cref='XmlCompletionData'/>.
115
/// <param name='val'>The <see cref='XmlCompletionData'/> to locate.</param>
117
/// <see langword='true'/> if the <see cref='XmlCompletionData'/> is contained in the collection;
118
/// otherwise, <see langword='false'/>.
120
/// <seealso cref='XmlCompletionDataCollection.IndexOf'/>
121
public bool Contains(XmlCompletionData val)
123
if (!string.IsNullOrEmpty (val.DisplayText)) {
124
return Contains (val.DisplayText);
129
public bool Contains(string name)
131
bool contains = false;
133
foreach (XmlCompletionData data in this) {
134
if (!string.IsNullOrEmpty (data.DisplayText)) {
135
if (data.DisplayText == name) {
146
/// Copies the <see cref='XmlCompletionDataCollection'/> values to a one-dimensional <see cref='Array'/> instance at the
149
/// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='XmlCompletionDataCollection'/>.</param>
150
/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
151
/// <exception cref='ArgumentException'>
152
/// <para><paramref name='array'/> is multidimensional.</para>
153
/// <para>-or-</para>
154
/// <para>The number of elements in the <see cref='XmlCompletionDataCollection'/> is greater than
155
/// the available space between <paramref name='arrayIndex'/> and the end of
156
/// <paramref name='array'/>.</para>
158
/// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
159
/// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
160
/// <seealso cref='Array'/>
161
public void CopyTo(XmlCompletionData[] array, int index)
163
List.CopyTo(array, index);
167
/// Copies the <see cref='XmlCompletionDataCollection'/> values to a one-dimensional <see cref='Array'/> instance at the
170
public void CopyTo(ICompletionData[] array, int index)
172
List.CopyTo(array, index);
176
/// Returns the index of a <see cref='XmlCompletionData'/> in
177
/// the <see cref='XmlCompletionDataCollection'/>.
179
/// <param name='val'>The <see cref='XmlCompletionData'/> to locate.</param>
181
/// The index of the <see cref='XmlCompletionData'/> of <paramref name='val'/> in the
182
/// <see cref='XmlCompletionDataCollection'/>, if found; otherwise, -1.
184
/// <seealso cref='XmlCompletionDataCollection.Contains'/>
185
public int IndexOf(XmlCompletionData val)
187
return List.IndexOf(val);
191
/// Inserts a <see cref='XmlCompletionData'/> into the <see cref='XmlCompletionDataCollection'/> at the specified index.
193
/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
194
/// <param name='val'>The <see cref='XmlCompletionData'/> to insert.</param>
195
/// <seealso cref='XmlCompletionDataCollection.Add'/>
196
public void Insert(int index, XmlCompletionData val)
198
List.Insert(index, val);
202
/// Returns an array of <see cref="ICompletionData"/> items.
204
/// <returns></returns>
205
public ICompletionData[] ToArray()
207
ICompletionData[] data = new ICompletionData[Count];
213
/// Returns an enumerator that can iterate through the <see cref='XmlCompletionDataCollection'/>.
215
/// <seealso cref='IEnumerator'/>
216
public new XmlCompletionDataEnumerator GetEnumerator()
218
return new XmlCompletionDataEnumerator(this);
222
/// Removes a specific <see cref='XmlCompletionData'/> from the <see cref='XmlCompletionDataCollection'/>.
224
/// <param name='val'>The <see cref='XmlCompletionData'/> to remove from the <see cref='XmlCompletionDataCollection'/>.</param>
225
/// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
226
public void Remove(XmlCompletionData val)
232
/// Enumerator that can iterate through a XmlCompletionDataCollection.
234
/// <seealso cref='IEnumerator'/>
235
/// <seealso cref='XmlCompletionDataCollection'/>
236
/// <seealso cref='XmlCompletionData'/>
237
public class XmlCompletionDataEnumerator : IEnumerator
239
IEnumerator baseEnumerator;
243
/// Initializes a new instance of <see cref='XmlCompletionDataEnumerator'/>.
245
public XmlCompletionDataEnumerator(XmlCompletionDataCollection mappings)
247
this.temp = ((IEnumerable)(mappings));
248
this.baseEnumerator = temp.GetEnumerator();
252
/// Gets the current <see cref='XmlCompletionData'/> in the <seealso cref='XmlCompletionDataCollection'/>.
254
public XmlCompletionData Current {
256
return ((XmlCompletionData)(baseEnumerator.Current));
260
object IEnumerator.Current {
262
return baseEnumerator.Current;
267
/// Advances the enumerator to the next <see cref='XmlCompletionData'/> of the <see cref='XmlCompletionDataCollection'/>.
269
public bool MoveNext()
271
return baseEnumerator.MoveNext();
275
/// Sets the enumerator to its initial position, which is before the first element in the <see cref='XmlCompletionDataCollection'/>.
279
baseEnumerator.Reset();