Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

C# -> VB: most pattern matching fails to convert

Open
#1,281 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp, visualbasic
Domain
tooling

Research direction

Start with VisitIsPatternExpression and the hoisting path in CommonConversions.ConvertToVariableDeclaratorOrNull, then review the six characterization tests on the linked branch. Done means type, negated, relational, and constant patterns convert to the shown VB equivalents without errors or invalid Is comparisons, with the full suite remaining green.

Written by the indexing model from the issue text.

Description

C# -> VB
Input code
class Picture
{
}

class TestClass
{
    bool NegatedType(object o) => o is not string;

    bool NegatedNamedType(object o) => o is not Picture;

    int NegatedDeclaration(object o)
    {
        if (o is not string s) return -1;
        return s.Length;
    }

    bool Relational(int i) => i is > 0;

    bool ValueConstant(int i) => i is 5;
}
Erroneous output
Friend Class Picture
End Class

Friend Class TestClass
    Private Function NegatedType(o As Object) As Boolean
        ''' Cannot convert IsPatternExpressionSyntax, System.ArgumentOutOfRangeException: ... (Parameter 'node')
        ''' Actual value was not string.
    End Function

    Private Function NegatedNamedType(o As Object) As Boolean
        ''' Cannot convert IsPatternExpressionSyntax, System.ArgumentOutOfRangeException: ... (Parameter 'node')
        ''' Actual value was not Picture.
    End Function

    ''' Cannot convert MethodDeclarationSyntax, System.ArgumentOutOfRangeException: ... (Parameter 'node')
    ''' Actual value was not string s.

    Private Function Relational(i As Integer) As Boolean
        ''' Cannot convert IsPatternExpressionSyntax, System.ArgumentOutOfRangeException: ... (Parameter 'node')
        ''' Actual value was > 0.
    End Function

    Private Function ValueConstant(i As Integer) As Boolean
        Return i Is 5
    End Function
End Class

Stack traces trimmed for readability. NegatedDeclaration loses its whole body, because the throw comes from the hoisting path in CommonConversions.ConvertToVariableDeclaratorOrNull rather than from the visitor.

ValueConstant is the case worth separating: no error is reported, and Is compares references in VB, so i Is 5 does not compile against a value type. The others at least say something.

Expected output
Friend Class Picture
End Class

Friend Class TestClass
    Private Function NegatedType(o As Object) As Boolean
        Return TypeOf o IsNot String
    End Function

    Private Function NegatedNamedType(o As Object) As Boolean
        Return TypeOf o IsNot Picture
    End Function

    Private Function NegatedDeclaration(o As Object) As Integer
        Dim s As String = Nothing
        If CSharpImpl.__Assign(s, TryCast(o, String)) Is Nothing Then Return -1
        Return s.Length
    End Function

    Private Function Relational(i As Integer) As Boolean
        Return i > 0
    End Function

    Private Function ValueConstant(i As Integer) As Boolean
        Return i = 5
    End Function
End Class

VisitIsPatternExpression handles only DeclarationPatternSyntax and ConstantPatternSyntax and throws for anything else, so type patterns, negated patterns and relational patterns all fail. They have direct VB equivalents, so these read as gaps rather than language differences.

Details
  • Product in use: the NuGet library, called through ProjectConversion.ConvertSingleAsync.
  • Version in use: master at 26060772. Also reproduces on NuGet 10.0.1.923
  • Did you see it working in a previous version, which? No
  • Any other relevant information to the issue, or your interest in contributing a fix.
    I have a branch with the fix and six characterization tests, full suite green: https://github.com/gherards99/CodeConverter/tree/vb-pattern-matching

Two related gaps are deliberately left out of it, since both need the tested expression evaluated once rather than repeated, which means introducing a temporary: property patterns (o is T { P: true }, l is { Count: > 0 }, same ArgumentOutOfRangeException) and ??= (NotSupportedException: CoalesceAssignmentExpression is not supported!). I would rather raise those separately if you agree with the approach here.

Target-typed new is #1112 and the branch covers it too. The branch also makes #983 report the failure instead of silently returning nothing.

Dominant language
C#
Stars
913
Forks
244
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from icsharpcode/CodeConverter

All issues in icsharpcode/CodeConverter

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.