Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / test-async-76.cs
1 // Compiler options: -r:../class/lib/net_4_x/Mono.Cecil.dll
2
3 using System;
4 using System.Threading.Tasks;
5 using Mono.Cecil;
6 using System.Reflection;
7 using System.Runtime.CompilerServices;
8
9 namespace N
10 {
11         class C
12         {
13         }
14
15         interface I<T>
16         {
17                 void Foo (T t);
18         }
19
20         class X : I<C>
21         {
22                 async void I<C>.Foo (C c)
23                 {
24                         await Task.Delay (1);
25                 }
26
27                 public static int Main ()
28                 {
29                         var m = typeof (X).GetMethod ("N.I<N.C>.Foo", BindingFlags.NonPublic | BindingFlags.Instance);
30                         var attr = m.GetCustomAttribute<AsyncStateMachineAttribute> ();
31                         if (attr == null)
32                                 return 1;
33
34                         var assembly = AssemblyDefinition.ReadAssembly (typeof (X).Assembly.Location);
35                         foreach (var t in assembly.MainModule.Types) {
36                                 PrintType (t, 0);
37                         }
38
39                         return 0;
40                 }
41  
42                 static void PrintType (TypeDefinition td, int indent)
43                 {
44                         if (td.IsNested && !string.IsNullOrEmpty (td.Namespace))
45                                 throw new ApplicationException ("BROKEN NESTED TYPE:");
46                         Console.WriteLine ("{2} Namespace: {0} Name: {1}", td.Namespace, td.Name, new string (' ', indent * 4));
47                         foreach (var tn in td.NestedTypes)
48                                 PrintType (tn, indent + 1);
49                 }
50         }
51 }