CodeConverter icon indicating copy to clipboard operation
CodeConverter copied to clipboard

VB -> C#: improve int const adjustments in some cases

Open TymurGubayev opened this issue 6 months ago • 0 comments

Is your feature request related to a problem? Please describe. I'm always frustrated when a hexadecimal constant is converted in a way I can't search for it anymore (in some cases).

VB.NET input:

Dim i As Integer = &H80040E19
If (i = &H80040E19) Then
End If

Current output:

int i = int.MinValue + 0x00040E19;
if (i == int.MinValue + 0x00040E19)
{
}

Describe the solution you'd like I think a much nicer output would be using unchecked instead of changing the constant literal, something like this:

int i = unchecked((int)0x80040E19);
if (i == unchecked((int)0x80040E19))
{
}

Describe alternatives you've considered Write a Roslyn replacement rule to restore the constants in a pass after CodeConverter is done.

Additional context None.

TymurGubayev avatar Dec 13 '23 10:12 TymurGubayev