+
+ if ((expression_method.ModFlags & Modifiers.ASYNC) != 0) {
+ //
+ // Host method is async. When WaitOnTask is set we wrap it with wait
+ //
+ // void AsyncWait (ref object $retval) {
+ // $retval = Host();
+ // ((Task)$retval).Wait(); // When WaitOnTask is set
+ // }
+ //
+ var p = new ParametersCompiled (
+ new Parameter (new TypeExpression (module.Compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null)
+ );
+
+ var method = new Method(host, new TypeExpression(module.Compiler.BuiltinTypes.Void, Location.Null),
+ Modifiers.PUBLIC | Modifiers.STATIC, new MemberName("AsyncWait"), p, null);
+
+ method.Block = new ToplevelBlock(method.Compiler, p, Location.Null);
+ method.Block.AddStatement(new StatementExpression (new SimpleAssign(
+ new SimpleName(p [0].Name, Location.Null),
+ new Invocation(new SimpleName(expression_method.MemberName.Name, Location.Null), new Arguments(0)),
+ Location.Null), Location.Null));
+
+ if (WaitOnTask) {
+ var task = new Cast (expression_method.TypeExpression, new SimpleName (p [0].Name, Location.Null), Location.Null);
+
+ method.Block.AddStatement (new StatementExpression (new Invocation (
+ new MemberAccess (task, "Wait", Location.Null),
+ new Arguments (0)), Location.Null));
+ }
+
+ host.AddMember(method);
+
+ expression_method = method;
+ }
+
+ host.CreateContainer();
+ host.DefineContainer();
+ host.Define();
+