Author: jpobst
Date: 2008-01-22 11:42:21 -0500 (Tue, 22 Jan 2008)
New Revision: 93545
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ControlTest.cs
Log:
2008-01-22 Jonathan Pobst <[EMAIL PROTECTED]>
* Control.cs: Implement a custom enumerator so people can delete
from the Controls collection while in a foreach.
[Fixes bug #355074]
2008-01-22 Jonathan Pobst <[EMAIL PROTECTED]>
* ControlTest.cs: Add test for bug #355074.
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2008-01-22 16:25:28 UTC (rev 93544)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2008-01-22 16:42:21 UTC (rev 93545)
@@ -1,3 +1,9 @@
+2008-01-22 Jonathan Pobst <[EMAIL PROTECTED]>
+
+ * Control.cs: Implement a custom enumerator so people can delete
+ from the Controls collection while in a foreach.
+ [Fixes bug #355074]
+
2008-01-22 Ivan N. Zlatev <[EMAIL PROTECTED]>
* PropertyGridView.cs: Fix focusing behavior:
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
2008-01-22 16:25:28 UTC (rev 93544)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
2008-01-22 16:42:21 UTC (rev 93545)
@@ -735,7 +735,7 @@
public IEnumerator
#endif
GetEnumerator () {
- return list.GetEnumerator();
+ return new ControlCollectionEnumerator (list);
}
internal IEnumerator GetAllEnumerator () {
@@ -973,6 +973,41 @@
return clone;
}
#endregion // ControlCollection Interface Methods
+
+ private class ControlCollectionEnumerator : IEnumerator
+ {
+ private ArrayList list;
+ int position = -1;
+
+ public ControlCollectionEnumerator (ArrayList
collection)
+ {
+ list = collection;
+ }
+
+ #region IEnumerator Members
+ public object Current {
+ get {
+ try {
+ return list[position];
+ } catch
(IndexOutOfRangeException) {
+ throw new
InvalidOperationException ();
+ }
+ }
+ }
+
+ public bool MoveNext ()
+ {
+ position++;
+ return (position < list.Count);
+ }
+
+ public void Reset ()
+ {
+ position = -1;
+ }
+
+ #endregion
+ }
}
#endregion // ControlCollection Class
Modified:
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
2008-01-22 16:25:28 UTC (rev 93544)
+++ trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
2008-01-22 16:42:21 UTC (rev 93545)
@@ -1,3 +1,7 @@
+2008-01-22 Jonathan Pobst <[EMAIL PROTECTED]>
+
+ * ControlTest.cs: Add test for bug #355074.
+
2008-01-18 Jonathan Pobst <[EMAIL PROTECTED]>
* FormTest.cs: Add test from James Purcell for bug #354669.
Modified:
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ControlTest.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ControlTest.cs
2008-01-22 16:25:28 UTC (rev 93544)
+++
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ControlTest.cs
2008-01-22 16:42:21 UTC (rev 93545)
@@ -2453,6 +2453,19 @@
Assert.AreEqual (new Point (225, 287),
button1.Location, "A3");
f.Dispose ();
}
+
+ [Test]
+ public void DisposeEnumerator ()
+ {
+ // We can modify the collection while looping through
it without crashing
+ Control c = new Control ();
+
+ c.Controls.Add (new Control ());
+ c.Controls.Add (new Control ());
+
+ foreach (Control c1 in c.Controls)
+ c.Controls.Remove (c1);
+ }
}
[TestFixture]
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches