2 // System.Web.SiteMapNodeCollection
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Lluis Sanchez Gual (lluis@novell.com)
9 // (C) 2005-2009 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
34 using System.Collections.Specialized;
37 using System.Web.UI.WebControls;
41 public class SiteMapNodeCollection : IList, IHierarchicalEnumerable
45 const string _siteMapNodeCollection_EmptyList = "SiteMapNodeCollection.EmptyList";
46 internal static SiteMapNodeCollection EmptyList
48 get { return (SiteMapNodeCollection) AppDomain.CurrentDomain.GetData (_siteMapNodeCollection_EmptyList); }
49 set { AppDomain.CurrentDomain.SetData (_siteMapNodeCollection_EmptyList, value); }
52 internal static SiteMapNodeCollection EmptyList;
55 static SiteMapNodeCollection ()
57 EmptyList = new SiteMapNodeCollection ();
58 EmptyList.list = ArrayList.ReadOnly (new ArrayList ());
61 public SiteMapNodeCollection ()
65 public SiteMapNodeCollection (int capacity)
67 list = new ArrayList (capacity);
70 public SiteMapNodeCollection (SiteMapNode value)
75 public SiteMapNodeCollection (SiteMapNode[] values)
77 AddRangeInternal (values);
80 public SiteMapNodeCollection (SiteMapNodeCollection values)
82 AddRangeInternal (values);
85 internal static SiteMapNodeCollection EmptyCollection {
86 get { return EmptyList; }
91 if (list == null) list = new ArrayList ();
96 public virtual int Count {
97 get { return list == null ? 0 : list.Count; }
100 public virtual bool IsSynchronized {
101 get { return false; }
104 public virtual object SyncRoot {
108 public virtual IEnumerator GetEnumerator ()
110 return list != null ? list.GetEnumerator () : Type.EmptyTypes.GetEnumerator ();
113 public virtual void Clear ()
115 if (list != null) list.Clear ();
118 public virtual void RemoveAt (int index)
120 List.RemoveAt (index);
123 public virtual int Add (SiteMapNode value)
126 throw new ArgumentNullException ("value");
127 return this.List.Add (value);
130 public virtual void AddRange (System.Web.SiteMapNode[] value)
132 this.AddRangeInternal (value);
135 public virtual void AddRange (SiteMapNodeCollection value)
137 this.AddRangeInternal (value);
140 internal virtual void AddRangeInternal (IList value)
143 throw new ArgumentNullException ("value");
145 List.AddRange (value);
148 public virtual bool Contains (SiteMapNode value)
150 return this.List.Contains (value);
153 public virtual void CopyTo (System.Web.SiteMapNode[] array, int index)
155 this.List.CopyTo (array, index);
158 public virtual int IndexOf (SiteMapNode value)
160 return this.List.IndexOf (value);
163 public virtual void Insert (int index, SiteMapNode value)
165 this.List.Insert (index, value);
168 protected virtual void OnValidate (object value)
170 if (!(value is SiteMapNode))
171 throw new ArgumentException ("Invalid type");
174 public static SiteMapNodeCollection ReadOnly (SiteMapNodeCollection collection)
176 SiteMapNodeCollection col = new SiteMapNodeCollection ();
177 if (collection.list != null)
178 col.list = ArrayList.ReadOnly (collection.list);
180 col.list = ArrayList.ReadOnly (new ArrayList ());
184 public virtual void Remove (SiteMapNode value)
186 this.List.Remove (value);
189 public virtual IHierarchyData GetHierarchyData (object enumeratedItem)
191 return enumeratedItem as IHierarchyData;
194 public SiteMapDataSourceView GetDataSourceView (SiteMapDataSource owner, string viewName)
196 return new SiteMapDataSourceView (owner, viewName, this);
199 public SiteMapHierarchicalDataSourceView GetHierarchicalDataSourceView ()
201 return new SiteMapHierarchicalDataSourceView (this);
204 public virtual SiteMapNode this [int index] {
205 get { return (SiteMapNode) this.List [index]; }
206 set { this.List [index] = value; }
209 public virtual bool IsFixedSize {
210 get { return List.IsFixedSize; }
213 public virtual bool IsReadOnly {
214 get { return list != null && list.IsReadOnly; }
217 #region IList Members
219 object IList.this [int index] {
220 get { return List [index]; }
221 set { OnValidate (value); List [index] = value; }
224 int IList.Add (object value)
227 return List.Add (value);
230 bool IList.Contains (object value)
232 return List.Contains (value);
235 int IList.IndexOf (object value)
237 return List.IndexOf (value);
240 void IList.Insert (int index, object value)
243 List.Insert (index, value);
246 void IList.Remove (object value)
252 void ICollection.CopyTo (Array array, int index)
254 List.CopyTo (array, index);
257 void IList.Clear () {
261 bool IList.IsFixedSize {
262 get { return IsFixedSize; }
265 bool IList.IsReadOnly {
266 get { return IsReadOnly; }
269 void IList.RemoveAt (int index) {
275 #region ICollection Members
278 int ICollection.Count {
279 get { return Count; }
282 bool ICollection.IsSynchronized {
283 get { return IsSynchronized; }
286 object ICollection.SyncRoot {
287 get { return SyncRoot; }
292 #region IEnumerable Members
294 IEnumerator IEnumerable.GetEnumerator () {
295 return GetEnumerator ();
300 #region IHierarchicalEnumerable Members
302 IHierarchyData IHierarchicalEnumerable.GetHierarchyData (object enumeratedItem) {
303 return GetHierarchyData (enumeratedItem);