PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/System.Web/System.Web/SiteMapNodeCollection.cs

https://bitbucket.org/danipen/mono
C# | 310 lines | 218 code | 62 blank | 30 comment | 15 complexity | 7286f151c7f749b7790e5690e664ee72 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. //
  2. // System.Web.SiteMapNodeCollection
  3. //
  4. // Authors:
  5. // Ben Maurer (bmaurer@users.sourceforge.net)
  6. // Lluis Sanchez Gual (lluis@novell.com)
  7. //
  8. // (C) 2003 Ben Maurer
  9. // (C) 2005-2009 Novell, Inc (http://www.novell.com)
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System.Collections;
  32. using System.Collections.Specialized;
  33. using System.Text;
  34. using System.Web.UI;
  35. using System.Web.UI.WebControls;
  36. namespace System.Web
  37. {
  38. public class SiteMapNodeCollection : IList, IHierarchicalEnumerable
  39. {
  40. ArrayList list;
  41. #if TARGET_JVM
  42. const string _siteMapNodeCollection_EmptyList = "SiteMapNodeCollection.EmptyList";
  43. internal static SiteMapNodeCollection EmptyList
  44. {
  45. get { return (SiteMapNodeCollection) AppDomain.CurrentDomain.GetData (_siteMapNodeCollection_EmptyList); }
  46. set { AppDomain.CurrentDomain.SetData (_siteMapNodeCollection_EmptyList, value); }
  47. }
  48. #else
  49. internal static SiteMapNodeCollection EmptyList;
  50. #endif
  51. static SiteMapNodeCollection ()
  52. {
  53. EmptyList = new SiteMapNodeCollection ();
  54. EmptyList.list = ArrayList.ReadOnly (new ArrayList ());
  55. }
  56. public SiteMapNodeCollection ()
  57. {
  58. }
  59. public SiteMapNodeCollection (int capacity)
  60. {
  61. list = new ArrayList (capacity);
  62. }
  63. public SiteMapNodeCollection (SiteMapNode value)
  64. {
  65. Add (value);
  66. }
  67. public SiteMapNodeCollection (SiteMapNode[] values)
  68. {
  69. AddRangeInternal (values);
  70. }
  71. public SiteMapNodeCollection (SiteMapNodeCollection values)
  72. {
  73. AddRangeInternal (values);
  74. }
  75. internal static SiteMapNodeCollection EmptyCollection {
  76. get { return EmptyList; }
  77. }
  78. ArrayList List {
  79. get {
  80. if (list == null) list = new ArrayList ();
  81. return list;
  82. }
  83. }
  84. public virtual int Count {
  85. get { return list == null ? 0 : list.Count; }
  86. }
  87. public virtual bool IsSynchronized {
  88. get { return false; }
  89. }
  90. public virtual object SyncRoot {
  91. get { return this; }
  92. }
  93. public virtual IEnumerator GetEnumerator ()
  94. {
  95. return list != null ? list.GetEnumerator () : Type.EmptyTypes.GetEnumerator ();
  96. }
  97. public virtual void Clear ()
  98. {
  99. if (list != null) list.Clear ();
  100. }
  101. public virtual void RemoveAt (int index)
  102. {
  103. List.RemoveAt (index);
  104. }
  105. public virtual int Add (SiteMapNode value)
  106. {
  107. if (value == null)
  108. throw new ArgumentNullException ("value");
  109. return this.List.Add (value);
  110. }
  111. public virtual void AddRange (System.Web.SiteMapNode[] value)
  112. {
  113. this.AddRangeInternal (value);
  114. }
  115. public virtual void AddRange (SiteMapNodeCollection value)
  116. {
  117. this.AddRangeInternal (value);
  118. }
  119. internal virtual void AddRangeInternal (IList value)
  120. {
  121. if (value == null)
  122. throw new ArgumentNullException ("value");
  123. List.AddRange (value);
  124. }
  125. public virtual bool Contains (SiteMapNode value)
  126. {
  127. return this.List.Contains (value);
  128. }
  129. public virtual void CopyTo (System.Web.SiteMapNode[] array, int index)
  130. {
  131. this.List.CopyTo (array, index);
  132. }
  133. public virtual int IndexOf (SiteMapNode value)
  134. {
  135. return this.List.IndexOf (value);
  136. }
  137. public virtual void Insert (int index, SiteMapNode value)
  138. {
  139. this.List.Insert (index, value);
  140. }
  141. protected virtual void OnValidate (object value)
  142. {
  143. if (!(value is SiteMapNode))
  144. throw new ArgumentException ("Invalid type");
  145. }
  146. public static SiteMapNodeCollection ReadOnly (SiteMapNodeCollection collection)
  147. {
  148. SiteMapNodeCollection col = new SiteMapNodeCollection ();
  149. if (collection.list != null)
  150. col.list = ArrayList.ReadOnly (collection.list);
  151. else
  152. col.list = ArrayList.ReadOnly (new ArrayList ());
  153. return col;
  154. }
  155. public virtual void Remove (SiteMapNode value)
  156. {
  157. this.List.Remove (value);
  158. }
  159. public virtual IHierarchyData GetHierarchyData (object enumeratedItem)
  160. {
  161. return enumeratedItem as IHierarchyData;
  162. }
  163. public SiteMapDataSourceView GetDataSourceView (SiteMapDataSource owner, string viewName)
  164. {
  165. return new SiteMapDataSourceView (owner, viewName, this);
  166. }
  167. public SiteMapHierarchicalDataSourceView GetHierarchicalDataSourceView ()
  168. {
  169. return new SiteMapHierarchicalDataSourceView (this);
  170. }
  171. public virtual SiteMapNode this [int index] {
  172. get { return (SiteMapNode) this.List [index]; }
  173. set { this.List [index] = value; }
  174. }
  175. public virtual bool IsFixedSize {
  176. get { return List.IsFixedSize; }
  177. }
  178. public virtual bool IsReadOnly {
  179. get { return list != null && list.IsReadOnly; }
  180. }
  181. #region IList Members
  182. object IList.this [int index] {
  183. get { return List [index]; }
  184. set { OnValidate (value); List [index] = value; }
  185. }
  186. int IList.Add (object value)
  187. {
  188. OnValidate (value);
  189. return List.Add (value);
  190. }
  191. bool IList.Contains (object value)
  192. {
  193. return List.Contains (value);
  194. }
  195. int IList.IndexOf (object value)
  196. {
  197. return List.IndexOf (value);
  198. }
  199. void IList.Insert (int index, object value)
  200. {
  201. OnValidate (value);
  202. List.Insert (index, value);
  203. }
  204. void IList.Remove (object value)
  205. {
  206. OnValidate (value);
  207. List.Remove (value);
  208. }
  209. void ICollection.CopyTo (Array array, int index)
  210. {
  211. List.CopyTo (array, index);
  212. }
  213. void IList.Clear () {
  214. Clear ();
  215. }
  216. bool IList.IsFixedSize {
  217. get { return IsFixedSize; }
  218. }
  219. bool IList.IsReadOnly {
  220. get { return IsReadOnly; }
  221. }
  222. void IList.RemoveAt (int index) {
  223. RemoveAt (index);
  224. }
  225. #endregion
  226. #region ICollection Members
  227. int ICollection.Count {
  228. get { return Count; }
  229. }
  230. bool ICollection.IsSynchronized {
  231. get { return IsSynchronized; }
  232. }
  233. object ICollection.SyncRoot {
  234. get { return SyncRoot; }
  235. }
  236. #endregion
  237. #region IEnumerable Members
  238. IEnumerator IEnumerable.GetEnumerator () {
  239. return GetEnumerator ();
  240. }
  241. #endregion
  242. #region IHierarchicalEnumerable Members
  243. IHierarchyData IHierarchicalEnumerable.GetHierarchyData (object enumeratedItem) {
  244. return GetHierarchyData (enumeratedItem);
  245. }
  246. #endregion
  247. }
  248. }