2 // System.Web.SiteMapNodeCollection
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Lluis Sanchez Gual (lluis@novell.com)
9 // (C) 2005 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.
34 using System.Collections;
35 using System.Collections.Specialized;
38 using System.Web.UI.WebControls;
42 public class SiteMapNodeCollection : IList, IHierarchicalEnumerable
45 internal static SiteMapNodeCollection EmptyList;
47 static SiteMapNodeCollection ()
49 EmptyList = new SiteMapNodeCollection ();
50 EmptyList.list = ArrayList.ReadOnly (new ArrayList ());
53 public SiteMapNodeCollection ()
57 public SiteMapNodeCollection (int capacity)
59 list = new ArrayList (capacity);
62 public SiteMapNodeCollection (SiteMapNode value)
67 public SiteMapNodeCollection (SiteMapNode[] values)
69 AddRangeInternal (values);
72 public SiteMapNodeCollection (SiteMapNodeCollection values)
74 AddRangeInternal (values);
77 internal static SiteMapNodeCollection EmptyCollection {
78 get { return EmptyList; }
83 if (list == null) list = new ArrayList ();
88 public virtual int Count {
89 get { return list == null ? 0 : list.Count; }
92 public virtual bool IsSynchronized {
96 public virtual object SyncRoot {
100 public virtual IEnumerator GetEnumerator ()
102 return list != null ? list.GetEnumerator () : Type.EmptyTypes.GetEnumerator ();
105 public virtual void Clear ()
107 if (list != null) list.Clear ();
110 public virtual void RemoveAt (int index)
112 List.RemoveAt (index);
115 public virtual int Add (SiteMapNode value)
118 throw new ArgumentNullException ("value");
119 return this.List.Add (value);
122 public virtual void AddRange (System.Web.SiteMapNode[] value)
124 this.AddRangeInternal (value);
127 public virtual void AddRange (SiteMapNodeCollection value)
129 this.AddRangeInternal (value);
132 internal virtual void AddRangeInternal (IList value)
135 throw new ArgumentNullException ("value");
137 List.AddRange (value);
140 public bool Contains (SiteMapNode value)
142 return this.List.Contains (value);
145 public void CopyTo (System.Web.SiteMapNode[] array, int index)
147 this.List.CopyTo (array, index);
150 public int IndexOf (SiteMapNode value)
152 return this.List.IndexOf (value);
155 public virtual void Insert (int index, SiteMapNode value)
157 this.List.Insert (index, value);
160 protected virtual void OnValidate (object value)
162 if (!(value is SiteMapNode))
163 throw new ArgumentException ("Invalid type");
166 public static SiteMapNodeCollection ReadOnly (SiteMapNodeCollection collection)
168 SiteMapNodeCollection col = new SiteMapNodeCollection ();
169 if (collection.list != null)
170 col.list = ArrayList.ReadOnly (collection.list);
172 col.list = ArrayList.ReadOnly (new ArrayList ());
176 public virtual void Remove (SiteMapNode value)
178 this.List.Remove (value);
181 public virtual IHierarchyData GetHierarchyData (object enumeratedItem)
183 return enumeratedItem as IHierarchyData;
186 public SiteMapDataSourceView GetDataSourceView (SiteMapDataSource owner, string viewName)
188 return new SiteMapDataSourceView (owner, viewName, this);
191 public SiteMapHierarchicalDataSourceView GetHierarchicalDataSourceView ()
193 return new SiteMapHierarchicalDataSourceView (this);
196 public virtual SiteMapNode this [int index] {
197 get { return (SiteMapNode) this.List [index]; }
198 set { this.List [index] = value; }
201 public virtual bool IsFixedSize {
202 get { return List.IsFixedSize; }
205 public virtual bool IsReadOnly {
206 get { return list != null && list.IsReadOnly; }
209 object IList.this [int index] {
210 get { return List [index]; }
211 set { OnValidate (value); List [index] = value; }
214 int IList.Add (object value)
217 return List.Add (value);
220 bool IList.Contains (object value)
222 return List.Contains (value);
225 int IList.IndexOf (object value)
227 return List.IndexOf (value);
230 void IList.Insert (int index, object value)
233 List.Insert (index, value);
236 void IList.Remove (object value)
242 void ICollection.CopyTo (Array array, int index)
244 List.CopyTo (array, index);