Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

VB -> C#: Select case with string and option compare Text #579

Closed
marcal opened this issue Jun 19, 2020 · 3 comments · Fixed by #582
Closed

VB -> C#: Select case with string and option compare Text #579

marcal opened this issue Jun 19, 2020 · 3 comments · Fixed by #582
Assignees
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@marcal
Copy link

marcal commented Jun 19, 2020

Hello,

There is a problem when I convert a code that has a select case (string) and the option (project) is option compare Text (and not Binary). when I run the converted program, the comparaison is binary instead of Text

Thank you for the help
Marc

Input code

call should return True
MessageBox.Show(Test("test"))


Private Function Test(astr_Temp As String) As Boolean
        Select Case astr_Temp
            Case "Test"
                Return True
            Case Else
                Return False

        End Select
    End Function

If relevant, please enter some example code here to reproduce the issue, or the steps taken to cause the issue.

Erroneous output

Returns False
MessageBox.Show(Conversions.ToString(Test("test")));
private bool Test(string astr_Temp)
        {
            switch (astr_Temp)
            {
                case "Test":
                    {
                        return true;
                    }

                default:
                    {
                        return false;
                    }
            }
        }
If relevant, the incorrectly converted output, or an exception with stack trace.

Expected output

It should return True
It could be (for example)
private bool Test(string astr_Temp)
        {
            switch (astr_Temp.ToUpperInvariant ())
            {
                case "TEST":
                    {
                        return true;
                    }

                default:
                    {
                        return false;
                    }
            }
        }
// Or Better 
private bool Test(string astr_Temp)
        {
            switch (true)
            {
                case bool  Tmp when  astr_Temp.Equals ("Test",StringComparison.InvariantCultureIgnoreCase ):
                    {
                        return true;
                    }
                case bool Tmp when astr_Temp.Equals("Test2", StringComparison.InvariantCultureIgnoreCase):
                    {
                        return true;
                    }
                default:
                    {
                        return false;
                    }
            }
        }

Details

  • Product in use: Last version
@marcal marcal added the VB -> C# Specific to VB -> C# conversion label Jun 19, 2020
@GrahamTheCoder
Copy link
Member

GrahamTheCoder commented Jun 19, 2020

Ah yes. Didn't know about that but it totally makes sense. I'll have a look soonish
It probably needs some null coalescing as well
Also the pattern in #323 could work, though it's hard to do for vs2017 since the syntax hadn't been invented yet

@marcal
Copy link
Author

marcal commented Jun 20, 2020

Hello,
You are right, the pattern in #323 should work too.

Thank you

@marcal
Copy link
Author

marcal commented Jun 28, 2020

Hello,

It is working perfectly with the last "Preview" version
Thank you

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants