Просмотр исходного кода

2002-05-01 Nick Drochak <[email protected]>

	* ArrayList.cs (Add & AddRange) : Throw exceptions where needed.

svn path=/trunk/mcs/; revision=4189
Nick Drochak 24 лет назад
Родитель
Сommit
7a335d40dd

+ 10 - 5
mcs/class/corlib/System.Collections/ArrayList.cs

@@ -298,13 +298,13 @@ namespace System.Collections {
 		// methods
 
 		public virtual int Add (object value) {
-			if (readOnly) {
-				throw new NotSupportedException ("Collection is read-only.");
-			}
+			if (readOnly)
+				throw new NotSupportedException ("ArrayList is read-only.");
+			if (fixedSize)
+				throw new NotSupportedException ("ArrayList is fixed size.");
 
-			if (count + 1 >= capacity) {
+			if (count + 1 >= capacity)
 				setSize (capacity * 2);
-			}
 
 			dataArray[count] = value;
 			version++;
@@ -312,6 +312,11 @@ namespace System.Collections {
 		}
 
 		public virtual void AddRange (ICollection c) {
+			if (null == c)
+				throw new ArgumentNullException ("c");
+			if (readOnly || fixedSize)
+				throw new NotSupportedException ();
+
 			int cc = c.Count;
 			if (count + cc >= capacity)
 				Capacity = cc < count? count * 2: count + cc + 1;

+ 4 - 0
mcs/class/corlib/System.Collections/ChangeLog

@@ -1,3 +1,7 @@
+2002-05-01  Nick Drochak  <[email protected]>
+
+	* ArrayList.cs (Add & AddRange) : Throw exceptions where needed.
+
 2002/05/01  Nick Drochak <[email protected]>
 
 	* ArrayList.cs (CopyTo) : Check parameters and throw exceptions