2 // Tests the using statement implementation
7 class MyDispose
: IDisposable
{
10 public void Dispose ()
17 // This class does not implement IDiposable, but has an implicit conversion
21 static public MyDispose x
;
32 public static implicit operator MyDispose (NoIDispose a
)
41 using (NoIDispose a
= new NoIDispose ()){
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 ()){
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.
73 using (MyDispose c
= new MyDispose ()){
75 throw new Exception ();
82 Console
.WriteLine ("Disposal on finally block works");
85 // This should test if `a' is non-null before calling dispose
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
103 if (NoIDispose
.x
.disposed
!= true)
106 Console
.WriteLine ("Implicit conversion from type to IDisposable pass");
108 MyDispose bb
= new MyDispose ();
112 if (bb
.disposed
== false)
115 Console
.WriteLine ("All tests pass");