if (array.Rank > 1)\r
throw new ArgumentException("array cannot be multidimensional");\r
\r
- System.Array.Copy (dataArray, 0, array, 0, this.count);\r
+ Array.Copy (dataArray, 0, array, 0, this.count);\r
}\r
\r
public virtual void CopyTo (Array array, int arrayIndex) {\r
if (this.count > array.Length - arrayIndex)\r
throw new ArgumentException("this ArrayList has more items than the space available in array from arrayIndex to the end of array");\r
\r
- System.Array.Copy (dataArray, 0, array, arrayIndex, this.count);\r
+ Array.Copy (dataArray, 0, array, arrayIndex, this.count);\r
}\r
\r
public virtual void CopyTo (int index, Array array,\r
if (this.count > array.Length - arrayIndex)\r
throw new ArgumentException("this ArrayList has more items than the space available in array from arrayIndex to the end of array");\r
\r
- System.Array.Copy (dataArray, index, array, arrayIndex, count);\r
+ Array.Copy (dataArray, index, array, arrayIndex, count);\r
}\r
\r
[Serializable]\r
private int idx;\r
private int start;\r
private int num;\r
+ private ArrayList enumeratee;\r
+ private long version;\r
\r
- internal ArrayListEnumerator(int index, int count, object[] items) {\r
+ internal ArrayListEnumerator(int index, int count, object[] items, ArrayList al, long ver) {\r
data = items;\r
start = index;\r
num = count;\r
idx = start - 1;\r
+ enumeratee = al;\r
+ version = ver;\r
}\r
\r
public object Clone ()\r
{\r
- return new ArrayListEnumerator (start, num, data);\r
+ return new ArrayListEnumerator (start, num, data, enumeratee, version);\r
}\r
\r
public virtual object Current {\r
}\r
}\r
public virtual bool MoveNext() {\r
+ if (enumeratee.version != version)\r
+ throw new InvalidOperationException();\r
if (++idx < start + num)\r
return true;\r
return false;\r
}\r
\r
public virtual IEnumerator GetEnumerator () {\r
- return new ArrayListEnumerator(0, this.Count, dataArray);\r
+ return new ArrayListEnumerator(0, this.Count, dataArray, this, this.version);\r
}\r
\r
private void ValidateRange(int index, int count) {\r
\r
public virtual IEnumerator GetEnumerator (int index, int count) {\r
ValidateRange(index, count);\r
- return new ArrayListEnumerator(index, count, dataArray);\r
+ return new ArrayListEnumerator(index, count, dataArray, this, this.version);\r
}\r
\r
public virtual ArrayList GetRange (int index, int count) {\r
if (IsReadOnly || IsFixedSize)\r
throw new NotSupportedException ();\r
\r
+ // Get a copy of the collection before the shift in case the collection\r
+ // is this. Otherwise the enumerator will be confused.\r
+ Array source = Array.CreateInstance(typeof(object), c.Count);\r
+ c.CopyTo(source, 0);\r
+\r
shiftElements (index, c.Count);\r
count += c.Count;\r
\r
- IEnumerator en = c.GetEnumerator();\r
- while (en.MoveNext())\r
- dataArray[index++] = en.Current;\r
+ foreach (object o in source)\r
+ dataArray[index++] = o;\r
\r
version++;\r
}\r