|
1 | | -using ICSharpCode.CodeConverter.Util.FromRoslyn; |
2 | | -using Microsoft.CodeAnalysis.VisualBasic; |
| 1 | +using Microsoft.CodeAnalysis.VisualBasic; |
| 2 | +using static Microsoft.CodeAnalysis.VisualBasic.VisualBasicExtensions; |
| 3 | +using ICSharpCode.CodeConverter.Util.FromRoslyn; |
3 | 4 |
|
4 | 5 | namespace ICSharpCode.CodeConverter.CSharp; |
5 | 6 |
|
@@ -446,20 +447,28 @@ public CSSyntax.BlockSyntax WithImplicitReturnStatements(VBSyntax.MethodBlockBas |
446 | 447 | CSSyntax.IdentifierNameSyntax csReturnVariableOrNull) |
447 | 448 | { |
448 | 449 | if (!node.MustReturn()) return convertedStatements; |
449 | | - if (_semanticModel.GetDeclaredSymbol(node) is { } ms && ms.ReturnsVoidOrAsyncTask()) { |
| 450 | + var methodSymbol = node switch { |
| 451 | + VBSyntax.MethodBlockSyntax mb => _semanticModel.GetDeclaredSymbol(mb.SubOrFunctionStatement), |
| 452 | + VBSyntax.AccessorBlockSyntax ab => _semanticModel.GetDeclaredSymbol(ab.AccessorStatement), |
| 453 | + _ => _semanticModel.GetDeclaredSymbol(node) |
| 454 | + } as IMethodSymbol; |
| 455 | + if (methodSymbol?.ReturnsVoidOrAsyncTask() == true) { |
450 | 456 | return convertedStatements; |
451 | 457 | } |
452 | 458 |
|
453 | 459 |
|
454 | 460 | var preBodyStatements = new List<CSSyntax.StatementSyntax>(); |
455 | 461 | var postBodyStatements = new List<CSSyntax.StatementSyntax>(); |
456 | 462 |
|
457 | | - var symbolNode = node.TypeSwitch( |
458 | | - (VBSyntax.MethodBlockSyntax mb) => (VisualBasicSyntaxNode)mb.SubOrFunctionStatement, |
459 | | - (VBSyntax.AccessorBlockSyntax ab) => ab.AccessorStatement, |
460 | | - _ => node |
461 | | - ); |
462 | | - var functionSym = ModelExtensions.GetDeclaredSymbol(_semanticModel, symbolNode); |
| 463 | + var symbol = node switch { |
| 464 | + VBSyntax.MethodBlockSyntax mb => _semanticModel.GetDeclaredSymbol(mb.SubOrFunctionStatement), |
| 465 | + VBSyntax.AccessorBlockSyntax ab => _semanticModel.GetDeclaredSymbol(ab.AccessorStatement), |
| 466 | + _ => null |
| 467 | + }; |
| 468 | + var functionSym = symbol switch { |
| 469 | + IMethodSymbol ms => ms, |
| 470 | + _ => _semanticModel.GetDeclaredSymbol(node) as IMethodSymbol |
| 471 | + }; |
463 | 472 | if (functionSym != null) { |
464 | 473 | var returnType = CommonConversions.GetTypeSyntax(functionSym.GetReturnType()); |
465 | 474 |
|
|
0 commit comments