1 // HtmlAgilityPack V1.0 - Simon Mourier <simon underscore mourier at hotmail dot com>
\r
3 using System.Collections;
\r
5 namespace HtmlAgilityPack
\r
8 /// Represents a list of mixed code fragments.
\r
10 public class MixedCodeDocumentFragmentList : IEnumerable
\r
14 private MixedCodeDocument _doc;
\r
15 private ArrayList _items = new ArrayList();
\r
19 #region Constructors
\r
21 internal MixedCodeDocumentFragmentList(MixedCodeDocument doc)
\r
31 /// Gets the Document
\r
33 public MixedCodeDocument Doc
\r
35 get { return _doc; }
\r
39 /// Gets the number of fragments contained in the list.
\r
43 get { return _items.Count; }
\r
47 /// Gets a fragment from the list using its index.
\r
49 public MixedCodeDocumentFragment this[int index]
\r
51 get { return _items[index] as MixedCodeDocumentFragment; }
\r
56 #region IEnumerable Members
\r
59 /// Gets an enumerator that can iterate through the fragment list.
\r
61 IEnumerator IEnumerable.GetEnumerator()
\r
63 return GetEnumerator();
\r
68 #region Public Methods
\r
71 /// Appends a fragment to the list of fragments.
\r
73 /// <param name="newFragment">The fragment to append. May not be null.</param>
\r
74 public void Append(MixedCodeDocumentFragment newFragment)
\r
76 if (newFragment == null)
\r
78 throw new ArgumentNullException("newFragment");
\r
80 _items.Add(newFragment);
\r
84 /// Gets an enumerator that can iterate through the fragment list.
\r
86 public MixedCodeDocumentFragmentEnumerator GetEnumerator()
\r
88 return new MixedCodeDocumentFragmentEnumerator(_items);
\r
92 /// Prepends a fragment to the list of fragments.
\r
94 /// <param name="newFragment">The fragment to append. May not be null.</param>
\r
95 public void Prepend(MixedCodeDocumentFragment newFragment)
\r
97 if (newFragment == null)
\r
99 throw new ArgumentNullException("newFragment");
\r
101 _items.Insert(0, newFragment);
\r
105 /// Remove a fragment from the list of fragments. If this fragment was not in the list, an exception will be raised.
\r
107 /// <param name="fragment">The fragment to remove. May not be null.</param>
\r
108 public void Remove(MixedCodeDocumentFragment fragment)
\r
110 if (fragment == null)
\r
112 throw new ArgumentNullException("fragment");
\r
114 int index = GetFragmentIndex(fragment);
\r
117 throw new IndexOutOfRangeException();
\r
123 /// Remove all fragments from the list.
\r
125 public void RemoveAll()
\r
131 /// Remove a fragment from the list of fragments, using its index in the list.
\r
133 /// <param name="index">The index of the fragment to remove.</param>
\r
134 public void RemoveAt(int index)
\r
136 //MixedCodeDocumentFragment frag = (MixedCodeDocumentFragment) _items[index];
\r
137 _items.RemoveAt(index);
\r
142 #region Internal Methods
\r
144 internal void Clear()
\r
149 internal int GetFragmentIndex(MixedCodeDocumentFragment fragment)
\r
151 if (fragment == null)
\r
153 throw new ArgumentNullException("fragment");
\r
155 for (int i = 0; i < _items.Count; i++)
\r
157 if ((_items[i]) == fragment)
\r
167 #region Nested type: MixedCodeDocumentFragmentEnumerator
\r
170 /// Represents a fragment enumerator.
\r
172 public class MixedCodeDocumentFragmentEnumerator : IEnumerator
\r
176 private int _index;
\r
177 private ArrayList _items;
\r
181 #region Constructors
\r
183 internal MixedCodeDocumentFragmentEnumerator(ArrayList items)
\r
194 /// Gets the current element in the collection.
\r
196 public MixedCodeDocumentFragment Current
\r
198 get { return (MixedCodeDocumentFragment) (_items[_index]); }
\r
203 #region IEnumerator Members
\r
206 /// Gets the current element in the collection.
\r
208 object IEnumerator.Current
\r
210 get { return (Current); }
\r
214 /// Advances the enumerator to the next element of the collection.
\r
216 /// <returns>true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.</returns>
\r
217 public bool MoveNext()
\r
220 return (_index < _items.Count);
\r
224 /// Sets the enumerator to its initial position, which is before the first element in the collection.
\r
226 public void Reset()
\r