Skip to content

Commit 0a7c2a2

Browse files
committed
Fix #1244: Avoid unnecessary code blocks in switch case sections
Only wrap switch case statements in a Block when a local variable declaration is present. Otherwise emit statements directly, eliminating the extra level of braces and indentation. https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
1 parent 2bb1568 commit 0a7c2a2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,10 @@ public override async Task<SyntaxList<StatementSyntax>> VisitSelectBlock(VBSynta
883883
if (!DefinitelyExits(csBlockStatements.LastOrDefault())) {
884884
csBlockStatements.Add(SyntaxFactory.BreakStatement());
885885
}
886-
var list = SingleStatement(SyntaxFactory.Block(csBlockStatements));
886+
var hasLocalDeclaration = csBlockStatements.Any(s => s.IsKind(SyntaxKind.LocalDeclarationStatement));
887+
var list = hasLocalDeclaration
888+
? SingleStatement(SyntaxFactory.Block(csBlockStatements))
889+
: SyntaxFactory.List(csBlockStatements);
887890
sections.Add(SyntaxFactory.SwitchSection(SyntaxFactory.List(labels), list));
888891
}
889892

0 commit comments

Comments
 (0)