CodeConverter icon indicating copy to clipboard operation
CodeConverter copied to clipboard

VB -> C#: Select Case involving a range needs cast

Open docfresh opened this issue 4 years ago • 3 comments

VB.Net input code

    Select Case u.userlevel
        Case userlevel.City_Staff To userlevel.Fixity_ROOT
            Return True
            Exit Function
    End Select

Erroneous output

        switch (u.userlevel)
        {
            case var @case when userlevel.City_Staff <= @case && @case <= userlevel.Fixity_ROOT:
                {
                    return true;
                    return default;
                }
        }

Expected output

adding a cast here seems to fix the problem.

        switch (u.userlevel)
        {
            case var @case when (int) userlevel.City_Staff <= @case && @case <= (int) userlevel.Fixity_ROOT:
                {
                    return true;
                    return default;
                }
        }

details

extension version 8.4.1

docfresh avatar Oct 29 '21 01:10 docfresh

Thanks for the report. Could you also let me know the definitions (or at least the types) of u.userlevel, userlevel.City_Staff, userlevel.Fixity_ROOT (I would guess the first is an int field/property and the other two are enum members, but would be good to know for sure)

GrahamTheCoder avatar Oct 29 '21 08:10 GrahamTheCoder

Sorry for the delay. u.userlevel is an integer, and the userlevel enum is Byte.

Public Class user
...
    Public userlevel As Integer
...
End Class

Public Enum userlevel As Byte
    City_Staff = 4
    Fixity_ROOT = 10
  End Enum

docfresh avatar Nov 03 '21 18:11 docfresh

Perfect, thanks!

GrahamTheCoder avatar Nov 04 '21 08:11 GrahamTheCoder