@@ -383,7 +383,15 @@ partial class {ns}{classDeclaration}
383
383
/// <param name="isTopLevel">True if directly from the type we're generating for, false for methods found on base interfaces</param>
384
384
void ProcessRefitMethod ( StringBuilder source , IMethodSymbol methodSymbol , bool isTopLevel )
385
385
{
386
- WriteMethodOpening ( source , methodSymbol , ! isTopLevel ) ;
386
+ var returnType = methodSymbol . ReturnType . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ;
387
+ var ( isAsync , @return , configureAwait ) = methodSymbol . ReturnType . MetadataName switch
388
+ {
389
+ "Task" => ( true , "await (" , ").ConfigureAwait(false)" ) ,
390
+ "Task`1" or "ValueTask`1" => ( true , "return await (" , ").ConfigureAwait(false)" ) ,
391
+ _ => ( false , "return " , "" ) ,
392
+ } ;
393
+
394
+ WriteMethodOpening ( source , methodSymbol , ! isTopLevel , isAsync ) ;
387
395
388
396
// Build the list of args for the array
389
397
var argList = new List < string > ( ) ;
@@ -411,7 +419,14 @@ void ProcessRefitMethod(StringBuilder source, IMethodSymbol methodSymbol, bool i
411
419
source . Append ( @$ "
412
420
var ______arguments = new object[] {{ { string . Join ( ", " , argList ) } }};
413
421
var ______func = requestBuilder.BuildRestResultFuncForMethod(""{ methodSymbol . Name } "", new global::System.Type[] {{ { string . Join ( ", " , typeList ) } }}{ genericString } );
414
- return ({ methodSymbol . ReturnType . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) } )______func(this.Client, ______arguments);
422
+ try
423
+ {{
424
+ { @return } ({ returnType } )______func(this.Client, ______arguments){ configureAwait } ;
425
+ }}
426
+ catch (global::System.Exception ex)
427
+ {{
428
+ throw ex;
429
+ }}
415
430
" ) ;
416
431
417
432
WriteMethodClosing ( source ) ;
@@ -500,14 +515,15 @@ void ProcessNonRefitMethod<TContext>(TContext context, Action<TContext, Diagnost
500
515
}
501
516
}
502
517
503
- void WriteMethodOpening ( StringBuilder source , IMethodSymbol methodSymbol , bool isExplicitInterface )
518
+ void WriteMethodOpening ( StringBuilder source , IMethodSymbol methodSymbol , bool isExplicitInterface , bool isAsync = false )
504
519
{
505
520
var visibility = ! isExplicitInterface ? "public " : string . Empty ;
521
+ var async = isAsync ? "async " : "" ;
506
522
507
523
source . Append ( @$ "
508
524
509
525
/// <inheritdoc />
510
- { visibility } { methodSymbol . ReturnType . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) } " ) ;
526
+ { visibility } { async } { methodSymbol . ReturnType . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) } ");
511
527
512
528
if( isExplicitInterface )
513
529
{
@@ -527,8 +543,8 @@ void WriteMethodOpening(StringBuilder source, IMethodSymbol methodSymbol, bool i
527
543
528
544
source. Append ( string . Join ( ", " , list ) ) ;
529
545
}
530
-
531
- source . Append ( @$ ") { GenerateConstraints ( methodSymbol . TypeParameters , isExplicitInterface ) }
546
+
547
+ source. Append ( @$ "){ GenerateConstraints ( methodSymbol . TypeParameters , isExplicitInterface ) }
532
548
{{" ) ;
533
549
}
534
550
0 commit comments