Skip to content

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

Open
GrahamTheCoder wants to merge 2 commits intoicsharpcode:masterfrom
GrahamTheCoder:claude/fix-issue-803-relational-switch-pattern
Open

Fix #803: Use C# 9 relational patterns for VB Case Is <op> constant#1251
GrahamTheCoder wants to merge 2 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

claude added 2 commits April 13, 2026 22:31
…> 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
@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

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