* TextBoxBase.cs: You can still change the selected text on a
[mono-project.git] / mcs / tests / test-53.cs
blob34cdd0c2f9473f04ea4e6013a6f6b95ba72b7461
1 //
2 // Tests the using statement implementation
3 //
4 using System;
5 using System.IO;
7 class MyDispose : IDisposable {
8 public bool disposed;
10 public void Dispose ()
12 disposed = true;
17 // This class does not implement IDiposable, but has an implicit conversion
18 // defined
20 class NoIDispose {
21 static public MyDispose x;
23 public NoIDispose ()
27 static NoIDispose ()
29 x = new MyDispose ();
32 public static implicit operator MyDispose (NoIDispose a)
34 return x;
38 class Y {
39 static void B ()
41 using (NoIDispose a = new NoIDispose ()){
47 class X {
48 static int Main ()
50 MyDispose copy_a, copy_b, copy_c;
53 // Test whether the two `a' and `b' get disposed
55 using (MyDispose a = new MyDispose (), b = new MyDispose ()){
56 copy_a = a;
57 copy_b = b;
60 if (!copy_a.disposed)
61 return 1;
62 if (!copy_b.disposed)
63 return 2;
65 Console.WriteLine ("Nested using clause disposed");
68 // See if the variable `b' is disposed if there is
69 // an error thrown inside the using block.
71 copy_c = null;
72 try {
73 using (MyDispose c = new MyDispose ()){
74 copy_c = c;
75 throw new Exception ();
77 } catch {}
79 if (!copy_c.disposed)
80 return 3;
81 else
82 Console.WriteLine ("Disposal on finally block works");
85 // This should test if `a' is non-null before calling dispose
86 // implicitly
88 using (MyDispose d = null){
91 Console.WriteLine ("Null test passed");
94 // This tests that a variable is permitted here if there is
95 // an implicit conversion to a type that implement IDisposable
97 using (NoIDispose a = new NoIDispose ()){
101 // See if we dispose the object that can be implicitly converted
102 // to IDisposable
103 if (NoIDispose.x.disposed != true)
104 return 4;
105 else
106 Console.WriteLine ("Implicit conversion from type to IDisposable pass");
108 MyDispose bb = new MyDispose ();
109 using (bb){
112 if (bb.disposed == false)
113 return 6;
115 Console.WriteLine ("All tests pass");
116 return 0;