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