Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoltan Varga <vargaz@gmail.com>2003-04-02 18:21:02 +0400
committerZoltan Varga <vargaz@gmail.com>2003-04-02 18:21:02 +0400
commitef1be2f9f33bb9dee774631bf28d7c773fa211ec (patch)
tree71d50f1e43048ddb7f6a2dba9bc9991b451d1193 /mcs/tests/test-188.cs
parent043354e2de35b467fd3122b28368365762dc3a7c (diff)
2003-04-02 Zoltan Varga <vargaz@freemail.hu>
* README.tests test-188.cs makefile: Added test-188.cs. svn path=/trunk/mcs/; revision=13025
Diffstat (limited to 'mcs/tests/test-188.cs')
-rw-r--r--mcs/tests/test-188.cs59
1 files changed, 59 insertions, 0 deletions
diff --git a/mcs/tests/test-188.cs b/mcs/tests/test-188.cs
new file mode 100644
index 00000000000..e33e525582e
--- /dev/null
+++ b/mcs/tests/test-188.cs
@@ -0,0 +1,59 @@
+//
+// Test that the foreach statement generated by mcs invokes the Dispose()
+// method even if the enumerator class returned by GetEnumerator () does not
+// implement IDisposable.
+//
+
+using System;
+
+public class Enumerator {
+
+ int counter;
+
+ public Enumerator () {
+ counter = 3;
+ }
+
+ public bool MoveNext () {
+ return (counter -- > 0);
+ }
+
+ public char Current {
+ get {
+ return 'a';
+ }
+ }
+}
+
+class RealEnumerator : Enumerator, IDisposable {
+
+ Coll c;
+
+ public RealEnumerator (Coll c) {
+ this.c = c;
+ }
+
+ public void Dispose () {
+ c.disposed = true;
+ }
+}
+
+public class Coll {
+
+ public bool disposed;
+
+ public Enumerator GetEnumerator () {
+ return new RealEnumerator (this);
+ }
+}
+
+class Test {
+
+ public static int Main(String[] args)
+ {
+ Coll coll = new Coll ();
+ foreach (char c in coll) {
+ }
+ return (coll.disposed ? 0 : 1);
+ }
+}