VB -> C#: Brackets needed around ternary expression
VB.Net input code
dim x as integer
x = if(true, 1, 2) + 3
Erroneous output
int x;
x = true ? 1 : 2 + 3;
Expected output
int x;
x = (true ? 1 : 2) + 3;
Details
A simplified example of a gotcha hit during a recent VB->C# project conversion using version 9.2.7.0. Simple enough to fix once found. Otherwise, the convertor seems to have worked perfectly. Cheers
Thanks for the bug report and feedback on general success!
In the online converter, the case you gave seems to work correctly. For ease of repro, do you have an example that fails when pasted into: https://icsharpcode.github.io/CodeConverter/
I simplified the example too much. The below yields the issue when pasted into the online converter.
dim i as integer = 0
dim a(If(i = 1, 2, 3)) as string
Converts to:
int i = 0;
var a = new string[i == 1 ? 2 : 3 + 1];
Instead of:
int i = 0;
var a = new string[(i == 1 ? 2 : 3) + 1];
So it looks like the problem is in the addition of 1 for C# array extents.
@Nward42 : I believe my PR will fix this issue.