Skip to content

Fix #803: Use C# 9 relational patterns for VB Case Is <op> constant#1251

Merged
GrahamTheCoder merged 5 commits intoicsharpcode:masterfrom
GrahamTheCoder:claude/fix-issue-803-relational-switch-pattern
Apr 18, 2026
Merged

Fix #803: Use C# 9 relational patterns for VB Case Is <op> constant#1251
GrahamTheCoder merged 5 commits intoicsharpcode:masterfrom
GrahamTheCoder:claude/fix-issue-803-relational-switch-pattern

Conversation

@GrahamTheCoder
Copy link
Copy Markdown
Member

@GrahamTheCoder GrahamTheCoder commented Apr 13, 2026

Fixes #803

When converting VB Select Case with Case Is < value, Case Is > value, etc. (RelationalCaseClauseSyntax), emit clean C# 9 relational patterns (case < 1000:) instead of the verbose case var @case when @case < 1000: pattern, for non-object, non-string comparisons where the case value is a constant expression.

Also handle RelationalPatternSyntax in the C#→VB converter so that C# 9 relational patterns round-trip correctly back to VB Case Is <op> value.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX

@GrahamTheCoder GrahamTheCoder force-pushed the claude/fix-issue-803-relational-switch-pattern branch from 9319003 to dc08ad9 Compare April 13, 2026 22:31
CS.SyntaxKind.GreaterThanEqualsToken => (SyntaxKind.CaseGreaterThanOrEqualClause, SyntaxKind.GreaterThanEqualsToken),
_ => throw new NotSupportedException($"Relational operator token {csTokenKind} not supported in VB case clause")
};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation in C# -> VB direction with no test

claude added 5 commits April 18, 2026 15:53
…> constant`

When converting VB `Select Case` with `Case Is < value`, `Case Is > value`,
etc. (RelationalCaseClauseSyntax), emit clean C# 9 relational patterns
(`case < 1000:`) instead of the verbose `case var @case when @case < 1000:`
pattern, for non-object, non-string comparisons where the case value is a
constant expression.

Also handle RelationalPatternSyntax in the C#→VB converter so that C# 9
relational patterns round-trip correctly back to VB `Case Is <op> value`.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
Tests that C# 9 switch statement relational patterns (case < 0:) convert
correctly to VB Case Is < 0 clauses, addressing the missing test noted
in code review.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
@GrahamTheCoder GrahamTheCoder force-pushed the claude/fix-issue-803-relational-switch-pattern branch from 3c098b1 to bccf8e0 Compare April 18, 2026 15:54
@GrahamTheCoder GrahamTheCoder merged commit 1315673 into icsharpcode:master Apr 18, 2026
3 checks passed
@GrahamTheCoder GrahamTheCoder deleted the claude/fix-issue-803-relational-switch-pattern branch April 18, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VB -> C#: Use pattern in switch cases to reduce unnecessary code

2 participants