[runtime] Fix DISABLE_REFLECTION_EMIT build.
[mono.git] / docs / HtmlAgilityPack / MixedCodeDocumentFragmentList.cs
1 // HtmlAgilityPack V1.0 - Simon Mourier <simon underscore mourier at hotmail dot com>\r
2 using System;\r
3 using System.Collections;\r
4 \r
5 namespace HtmlAgilityPack\r
6 {\r
7     /// <summary>\r
8     /// Represents a list of mixed code fragments.\r
9     /// </summary>\r
10     public class MixedCodeDocumentFragmentList : IEnumerable\r
11     {\r
12         #region Fields\r
13 \r
14         private MixedCodeDocument _doc;\r
15         private ArrayList _items = new ArrayList();\r
16 \r
17         #endregion\r
18 \r
19         #region Constructors\r
20 \r
21         internal MixedCodeDocumentFragmentList(MixedCodeDocument doc)\r
22         {\r
23             _doc = doc;\r
24         }\r
25 \r
26         #endregion\r
27 \r
28         #region Properties\r
29 \r
30         ///<summary>\r
31         /// Gets the Document\r
32         ///</summary>\r
33         public MixedCodeDocument Doc\r
34         {\r
35             get { return _doc; }\r
36         }\r
37 \r
38         /// <summary>\r
39         /// Gets the number of fragments contained in the list.\r
40         /// </summary>\r
41         public int Count\r
42         {\r
43             get { return _items.Count; }\r
44         }\r
45 \r
46         /// <summary>\r
47         /// Gets a fragment from the list using its index.\r
48         /// </summary>\r
49         public MixedCodeDocumentFragment this[int index]\r
50         {\r
51             get { return _items[index] as MixedCodeDocumentFragment; }\r
52         }\r
53 \r
54         #endregion\r
55 \r
56         #region IEnumerable Members\r
57 \r
58         /// <summary>\r
59         /// Gets an enumerator that can iterate through the fragment list.\r
60         /// </summary>\r
61         IEnumerator IEnumerable.GetEnumerator()\r
62         {\r
63             return GetEnumerator();\r
64         }\r
65 \r
66         #endregion\r
67 \r
68         #region Public Methods\r
69 \r
70         /// <summary>\r
71         /// Appends a fragment to the list of fragments.\r
72         /// </summary>\r
73         /// <param name="newFragment">The fragment to append. May not be null.</param>\r
74         public void Append(MixedCodeDocumentFragment newFragment)\r
75         {\r
76             if (newFragment == null)\r
77             {\r
78                 throw new ArgumentNullException("newFragment");\r
79             }\r
80             _items.Add(newFragment);\r
81         }\r
82 \r
83         /// <summary>\r
84         /// Gets an enumerator that can iterate through the fragment list.\r
85         /// </summary>\r
86         public MixedCodeDocumentFragmentEnumerator GetEnumerator()\r
87         {\r
88             return new MixedCodeDocumentFragmentEnumerator(_items);\r
89         }\r
90 \r
91         /// <summary>\r
92         /// Prepends a fragment to the list of fragments.\r
93         /// </summary>\r
94         /// <param name="newFragment">The fragment to append. May not be null.</param>\r
95         public void Prepend(MixedCodeDocumentFragment newFragment)\r
96         {\r
97             if (newFragment == null)\r
98             {\r
99                 throw new ArgumentNullException("newFragment");\r
100             }\r
101             _items.Insert(0, newFragment);\r
102         }\r
103 \r
104         /// <summary>\r
105         /// Remove a fragment from the list of fragments. If this fragment was not in the list, an exception will be raised.\r
106         /// </summary>\r
107         /// <param name="fragment">The fragment to remove. May not be null.</param>\r
108         public void Remove(MixedCodeDocumentFragment fragment)\r
109         {\r
110             if (fragment == null)\r
111             {\r
112                 throw new ArgumentNullException("fragment");\r
113             }\r
114             int index = GetFragmentIndex(fragment);\r
115             if (index == -1)\r
116             {\r
117                 throw new IndexOutOfRangeException();\r
118             }\r
119             RemoveAt(index);\r
120         }\r
121 \r
122         /// <summary>\r
123         /// Remove all fragments from the list.\r
124         /// </summary>\r
125         public void RemoveAll()\r
126         {\r
127             _items.Clear();\r
128         }\r
129 \r
130         /// <summary>\r
131         /// Remove a fragment from the list of fragments, using its index in the list.\r
132         /// </summary>\r
133         /// <param name="index">The index of the fragment to remove.</param>\r
134         public void RemoveAt(int index)\r
135         {\r
136             //MixedCodeDocumentFragment frag = (MixedCodeDocumentFragment) _items[index];\r
137             _items.RemoveAt(index);\r
138         }\r
139 \r
140         #endregion\r
141 \r
142         #region Internal Methods\r
143 \r
144         internal void Clear()\r
145         {\r
146             _items.Clear();\r
147         }\r
148 \r
149         internal int GetFragmentIndex(MixedCodeDocumentFragment fragment)\r
150         {\r
151             if (fragment == null)\r
152             {\r
153                 throw new ArgumentNullException("fragment");\r
154             }\r
155             for (int i = 0; i < _items.Count; i++)\r
156             {\r
157                 if ((_items[i]) == fragment)\r
158                 {\r
159                     return i;\r
160                 }\r
161             }\r
162             return -1;\r
163         }\r
164 \r
165         #endregion\r
166 \r
167         #region Nested type: MixedCodeDocumentFragmentEnumerator\r
168 \r
169         /// <summary>\r
170         /// Represents a fragment enumerator.\r
171         /// </summary>\r
172         public class MixedCodeDocumentFragmentEnumerator : IEnumerator\r
173         {\r
174             #region Fields\r
175 \r
176             private int _index;\r
177             private ArrayList _items;\r
178 \r
179             #endregion\r
180 \r
181             #region Constructors\r
182 \r
183             internal MixedCodeDocumentFragmentEnumerator(ArrayList items)\r
184             {\r
185                 _items = items;\r
186                 _index = -1;\r
187             }\r
188 \r
189             #endregion\r
190 \r
191             #region Properties\r
192 \r
193             /// <summary>\r
194             /// Gets the current element in the collection.\r
195             /// </summary>\r
196             public MixedCodeDocumentFragment Current\r
197             {\r
198                 get { return (MixedCodeDocumentFragment) (_items[_index]); }\r
199             }\r
200 \r
201             #endregion\r
202 \r
203             #region IEnumerator Members\r
204 \r
205             /// <summary>\r
206             /// Gets the current element in the collection.\r
207             /// </summary>\r
208             object IEnumerator.Current\r
209             {\r
210                 get { return (Current); }\r
211             }\r
212 \r
213             /// <summary>\r
214             /// Advances the enumerator to the next element of the collection.\r
215             /// </summary>\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
218             {\r
219                 _index++;\r
220                 return (_index < _items.Count);\r
221             }\r
222 \r
223             /// <summary>\r
224             /// Sets the enumerator to its initial position, which is before the first element in the collection.\r
225             /// </summary>\r
226             public void Reset()\r
227             {\r
228                 _index = -1;\r
229             }\r
230 \r
231             #endregion\r
232         }\r
233 \r
234         #endregion\r
235     }\r
236 }