Skip to content

Commit c671679

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 f0d557f commit c671679

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
@@ -892,7 +892,10 @@ public override async Task<SyntaxList<StatementSyntax>> VisitSelectBlock(VBSynta
892892
if (!DefinitelyExits(csBlockStatements.LastOrDefault())) {
893893
csBlockStatements.Add(SyntaxFactory.BreakStatement());
894894
}
895-
var list = SingleStatement(SyntaxFactory.Block(csBlockStatements));
895+
var hasLocalDeclaration = csBlockStatements.Any(s => s.IsKind(SyntaxKind.LocalDeclarationStatement));
896+
var list = hasLocalDeclaration
897+
? SingleStatement(SyntaxFactory.Block(csBlockStatements))
898+
: SyntaxFactory.List(csBlockStatements);
896899
sections.Add(SyntaxFactory.SwitchSection(SyntaxFactory.List(labels), list));
897900
}
898901

0 commit comments

Comments
 (0)