Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / delegate-disposed-hashcode.cs
1 using System;
2
3 // Regression test for bug #59235
4
5 public static class Program {
6         delegate void MyDel (int i, int j);
7
8         public static void Main (string[] args) {
9                 var o = new MyTarget ();
10                 Console.WriteLine ("Hashcode1: " + o.GetHashCode ());
11
12                 MyDel d = o.DoStuff;
13                 Console.WriteLine ("Hashcode2: " + d.GetHashCode ());
14                 Console.WriteLine ("Hashcode3: " + o.GetHashCode ());
15
16                 o.Dispose ();
17                 Console.WriteLine ("Hashcode4: " + d.GetHashCode ());
18         }
19
20         class MyTarget : IDisposable {
21                 public int counter = 0;
22                 bool avail = true;
23
24                 public void DoStuff (int i, int j) {
25                         counter += i + j;
26                 }
27
28                 public void Dispose () {
29                         avail = false;
30                 }
31
32                 public override int GetHashCode () {
33                         if (!avail)
34                                 throw new ObjectDisposedException ("MyTarget is dead");
35                         return counter.GetHashCode ();
36                 }
37         }
38 }