@@ -70,6 +70,11 @@ static partial class BindingSyntaxFactory {
7070 foreach ( var parameter in delegateType . Delegate . Parameters [ ..^ 1 ] ) {
7171 noNSErrorArgs . Add ( Argument ( IdentifierName ( GetTaskCallbackParameterName ( parameter . Name ) ) ) ) ;
7272 }
73+ var resultsArgs = noNSErrorArgs . ToImmutable ( ) ;
74+ var resultArgsSyntax = resultsArgs . Length == 1
75+ ? resultsArgs [ 0 ]
76+ : Argument ( New ( resultsArgs ) ) ;
77+
7378 // update the if to include the result setting, we are doing by hand to fix the indentation to match monos
7479 ifErrorNotNull = IfStatement (
7580 attributeLists : default ,
@@ -87,7 +92,7 @@ static partial class BindingSyntaxFactory {
8792 ExpressionStatement (
8893 TcsSetResult (
8994 tcsVariableName : completionSourceName ,
90- arguments : [ Argument ( New ( noNSErrorArgs . ToImmutable ( ) ) ) ]
95+ arguments : [ resultArgsSyntax ]
9196 )
9297 ) . WithLeadingTrivia ( LineFeed , Tab , Tab )
9398 ) . WithLeadingTrivia ( LineFeed , Tab )
@@ -101,11 +106,17 @@ static partial class BindingSyntaxFactory {
101106 foreach ( var parameter in delegateType . Delegate . Parameters ) {
102107 arguments . Add ( Argument ( IdentifierName ( GetTaskCallbackParameterName ( parameter . Name ) ) ) ) ;
103108 }
109+
110+ var argList = arguments . ToImmutable ( ) ;
104111 // return a single expression that sets the result of the tcs
112+ var argSyntax = argList . Length == 1
113+ ? argList [ 0 ]
114+ : Argument ( New ( argList ) ) ;
115+
105116 return ExpressionStatement (
106117 TcsSetResult (
107118 tcsVariableName : completionSourceName ,
108- arguments : [ Argument ( New ( arguments . ToImmutable ( ) ) ) ]
119+ arguments : [ argSyntax ]
109120 )
110121 ) . WithLeadingTrivia ( Tab ) ;
111122 }
@@ -140,6 +151,28 @@ internal static ExpressionSyntax GetCallbackDeclaration (in TypeInfo delegateTyp
140151 . WithBlock ( block ) ;
141152 }
142153
154+ /// <summary>
155+ /// Generates an invocation expression for the synchronous part of an async method wrapper.
156+ /// </summary>
157+ /// <param name="method">The method to be called.</param>
158+ /// <returns>An invocation expression syntax.</returns>
159+ internal static ExpressionSyntax ExecuteSyncCall ( in Method method )
160+ {
161+ // retrieve the last parameter from the method, since that should be the completion handler
162+ var completionHandler = GetCallbackDeclaration ( method . Parameters [ ^ 1 ] . Type ) ;
163+ var arguments = ImmutableArray . CreateBuilder < ArgumentSyntax > ( method . Parameters . Length ) ;
164+ // build the arguments for the method call, those are the same arguments as the method parameters but the last one
165+ foreach ( var parameter in method . Parameters [ ..^ 1 ] ) {
166+ arguments . Add ( Argument ( IdentifierName ( parameter . Name ) ) ) ;
167+ }
168+ // add the completion handler as the last argument
169+ arguments . Add ( Argument ( completionHandler ) ) ;
170+
171+ var argumentList = ArgumentList (
172+ SeparatedList < ArgumentSyntax > ( arguments . ToSyntaxNodeOrTokenArray ( ) ) ) ;
173+ return InvocationExpression ( IdentifierName ( method . Name ) . WithTrailingTrivia ( Space ) ) . WithArgumentList ( argumentList ) ;
174+ }
175+
143176 /// <summary>
144177 /// Generates an invocation expression for sending an Objective-C message.
145178 /// </summary>
0 commit comments