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
44 internal static SiteMapNodeCollection EmptyList;
46 static SiteMapNodeCollection ()
48 EmptyList = new SiteMapNodeCollection ();
49 EmptyList.list = ArrayList.ReadOnly (new ArrayList ());
52 public SiteMapNodeCollection ()
56 public SiteMapNodeCollection (int capacity)
58 list = new ArrayList (capacity);
61 public SiteMapNodeCollection (SiteMapNode value)
66 public SiteMapNodeCollection (SiteMapNode[] values)
68 AddRangeInternal (values);
71 public SiteMapNodeCollection (SiteMapNodeCollection values)
73 AddRangeInternal (values);
76 internal static SiteMapNodeCollection EmptyCollection {
77 get { return EmptyList; }
82 if (list == null) list = new ArrayList ();
87 public virtual int Count {
88 get { return list == null ? 0 : list.Count; }
91 public virtual bool IsSynchronized {
95 public virtual object SyncRoot {
99 public virtual IEnumerator GetEnumerator ()
101 return list != null ? list.GetEnumerator () : Type.EmptyTypes.GetEnumerator ();
104 public virtual void Clear ()
106 if (list != null) list.Clear ();
109 public virtual void RemoveAt (int index)
111 List.RemoveAt (index);
114 public virtual int Add (SiteMapNode value)
117 throw new ArgumentNullException ("value");
118 return this.List.Add (value);
121 public virtual void AddRange (System.Web.SiteMapNode[] value)
123 this.AddRangeInternal (value);
126 public virtual void AddRange (SiteMapNodeCollection value)
128 this.AddRangeInternal (value);
131 internal virtual void AddRangeInternal (IList value)
134 throw new ArgumentNullException ("value");
136 List.AddRange (value);
139 public virtual bool Contains (SiteMapNode value)
141 return this.List.Contains (value);
144 public virtual void CopyTo (System.Web.SiteMapNode[] array, int index)
146 this.List.CopyTo (array, index);
149 public virtual int IndexOf (SiteMapNode value)
151 return this.List.IndexOf (value);
154 public virtual void Insert (int index, SiteMapNode value)
156 this.List.Insert (index, value);
159 protected virtual void OnValidate (object value)
161 if (!(value is SiteMapNode))
162 throw new ArgumentException ("Invalid type");
165 public static SiteMapNodeCollection ReadOnly (SiteMapNodeCollection collection)
167 SiteMapNodeCollection col = new SiteMapNodeCollection ();
168 if (collection.list != null)
169 col.list = ArrayList.ReadOnly (collection.list);
171 col.list = ArrayList.ReadOnly (new ArrayList ());
175 public virtual void Remove (SiteMapNode value)
177 this.List.Remove (value);
180 public virtual IHierarchyData GetHierarchyData (object enumeratedItem)
182 return enumeratedItem as IHierarchyData;
185 public SiteMapDataSourceView GetDataSourceView (SiteMapDataSource owner, string viewName)
187 return new SiteMapDataSourceView (owner, viewName, this);
190 public SiteMapHierarchicalDataSourceView GetHierarchicalDataSourceView ()
192 return new SiteMapHierarchicalDataSourceView (this);
195 public virtual SiteMapNode this [int index] {
196 get { return (SiteMapNode) this.List [index]; }
197 set { this.List [index] = value; }
200 public virtual bool IsFixedSize {
201 get { return List.IsFixedSize; }
204 public virtual bool IsReadOnly {
205 get { return list != null && list.IsReadOnly; }
208 #region IList Members
210 object IList.this [int index] {
211 get { return List [index]; }
212 set { OnValidate (value); List [index] = value; }
215 int IList.Add (object value)
218 return List.Add (value);
221 bool IList.Contains (object value)
223 return List.Contains (value);
226 int IList.IndexOf (object value)
228 return List.IndexOf (value);
231 void IList.Insert (int index, object value)
234 List.Insert (index, value);
237 void IList.Remove (object value)
243 void ICollection.CopyTo (Array array, int index)
245 List.CopyTo (array, index);
248 void IList.Clear () {
252 bool IList.IsFixedSize {
253 get { return IsFixedSize; }
256 bool IList.IsReadOnly {
257 get { return IsReadOnly; }
260 void IList.RemoveAt (int index) {
266 #region ICollection Members
269 int ICollection.Count {
270 get { return Count; }
273 bool ICollection.IsSynchronized {
274 get { return IsSynchronized; }
277 object ICollection.SyncRoot {
278 get { return SyncRoot; }
283 #region IEnumerable Members
285 IEnumerator IEnumerable.GetEnumerator () {
286 return GetEnumerator ();
291 #region IHierarchicalEnumerable Members
293 IHierarchyData IHierarchicalEnumerable.GetHierarchyData (object enumeratedItem) {
294 return GetHierarchyData (enumeratedItem);