Merge pull request #15293 from lewing/wasm-clean
[mono-project.git] / mcs / tests / test-async-35.cs
blobe04a810ebceed00ddd87d14c43e48053a821fe4a
1 using System;
2 using System.Reflection;
3 using System.Threading.Tasks;
4 using System.Runtime.CompilerServices;
5 using System.Linq;
7 namespace N.M
9 class C
11 public static async Task<int> AsyncMethod ()
13 await Task.Delay (1);
14 return 0;
17 public static async Task NestedAsyncAnonymousMethod ()
19 Action a = async delegate {
20 await Task.Yield();
23 await Task.Yield();
26 public static int Main ()
28 var m = typeof (C).GetMethod ("AsyncMethod");
29 var attr = m.GetCustomAttribute<AsyncStateMachineAttribute> ();
30 if (attr == null)
31 return 1;
33 if (attr.StateMachineType == null)
34 return 2;
36 Func<Task<int>> a = async () => await AsyncMethod ();
38 var c = typeof (C).GetMethods (BindingFlags.NonPublic | BindingFlags.Static).Where (l =>
39 l.IsDefined (typeof (AsyncStateMachineAttribute))).Count ();
41 if (c != 1)
42 return 3;
45 m = typeof (C).GetMethod ("NestedAsyncAnonymousMethod");
46 attr = m.GetCustomAttribute<AsyncStateMachineAttribute> ();
47 if (attr == null)
48 return 10;
50 if (attr.StateMachineType == null)
51 return 11;
53 var n = typeof (C).GetNestedTypes (BindingFlags.NonPublic).Single (l => l.Name.Contains ("NestedAsyncAnonymousMethod"));
54 if (n == null)
55 return 12;
57 m = n.GetMethods (BindingFlags.NonPublic | BindingFlags.Static).Single (l => l.Name.Contains ("m__"));
59 attr = m.GetCustomAttribute<AsyncStateMachineAttribute> ();
60 if (attr == null)
61 return 13;
63 if (attr.StateMachineType == null)
64 return 14;
66 return 0;