// Duncan Mak (duncan@ximian.com)
// Gonzalo Paniagua Javier (gonzalo@novell.com)
//
-// Copyright (c) 2002-2004 Novell, Inc. (http://www.novell.com)
-//
-
+// Copyright (c) 2002-2005 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using System.Collections;
+using System.Security.Permissions;
namespace System.Web.UI {
+ // CAS
+ [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class ControlCollection : ICollection, IEnumerable
{
Control owner;
this.owner = owner;
}
- public int Count {
+ public
+#if NET_2_0
+ virtual
+#endif
+ int Count {
get { return count; }
}
public virtual void Add (Control child)
{
if (child == null)
- throw new ArgumentNullException ();
+ throw new ArgumentNullException ("child");
if (readOnly)
- throw new HttpException ();
+ throw new HttpException (Locale.GetText ("Collection is read-only."));
+
+ if (Object.ReferenceEquals (owner, child))
+ throw new HttpException (Locale.GetText ("Cannot add collection's owner."));
EnsureControls ();
version++;
throw new ArgumentOutOfRangeException ();
if (readOnly)
- throw new HttpException ();
+ throw new HttpException (Locale.GetText ("Collection is read-only."));
+
+ if (Object.ReferenceEquals (owner, child))
+ throw new HttpException (Locale.GetText ("Cannot add collection's owner."));
if (index == -1) {
Add (child);
return (controls != null && Array.IndexOf (controls, c) != -1);
}
- public void CopyTo (Array array, int index)
+ public
+#if NET_2_0
+ virtual
+#endif
+ void CopyTo (Array array, int index)
{
if (controls == null)
return;
- controls.CopyTo (array, index);
+ // can't use controls.CopyTo (array, index);
+ // as we do not allocate it based on the true
+ // numbers of items we have in the collection
+ // so we must re-implement Array.CopyTo :(
+
+ if (array == null)
+ throw new ArgumentNullException ("array");
+ if (index + count > array.GetLowerBound (0) + array.GetLength (0))
+ throw new ArgumentException ();
+ if (array.Rank > 1)
+ throw new RankException (Locale.GetText ("Only single dimension arrays are supported."));
+ if (index < 0)
+ throw new ArgumentOutOfRangeException ("index", Locale.GetText ("Value has to be >= 0."));
+
+ for (int i=0; i < count; i++)
+ array.SetValue (controls [i], i + index);
}
- public IEnumerator GetEnumerator ()
+ public
+#if NET_2_0
+ virtual
+#endif
+ IEnumerator GetEnumerator ()
{
return new SimpleEnumerator (this);
}
public virtual int IndexOf (Control c)
{
- if (controls == null)
+ if (controls == null || c == null)
return -1;
return Array.IndexOf (controls, c);