c# – Visual Studio – How to find string equals evaluations in vb.net code

0
65

I need to convert a bunch of VB.NET code to C#. Instant C# is a great helper but one area… string case-insensitive VB.NET code.

Ahead of conversion, I would like to find a way to search for the VB.NET code that does string equals evaluations and change them to use String.Compare(x,y,true)=0.

Is there a way in Visual Studio 2017 to find these string evaluations? Maybe leveraging .NET Compiler Platform SDK?

For example Test routine would be changed like representative of Test2 routine then converted to C#.

Option Compare Text
.
.
.
      Private Sub Test()
        Dim x as string = "x"
        Dim y as string = "y"

        If x = y then msgbox("They match")

      End Sub

      Private Sub Test2()
        Dim x as string = "x"
        Dim y as string = "y"

        If String.Compare(x, y, True) = 0 then msgbox("They match")

      End Sub

C# converted output below

  private static void Test()
  {
    string x = "x";
    string y = "y";

    if ((x ?? string.Empty) == (y ?? string.Empty))
    {
      MessageBox.Show("They match");
    }

  }

  private static void Test2()
  {
    string x = "x";
    string y = "y";

    if (string.Compare(x, y, true) == 0)
    {
      MessageBox.Show("They match");
    }

  }

LEAVE A REPLY

Please enter your comment!
Please enter your name here