icsharpcode / CodeConverter

Convert code from C# to VB.NET and vice versa using Roslyn
https://icsharpcode.github.io/CodeConverter/
MIT License
826 stars 216 forks source link

VB -> C#: Non-Optional parameters can't follow optional ones #1057

Closed TymurGubayev closed 9 months ago

TymurGubayev commented 10 months ago

VB.Net input code

Sub S(Optional a As Integer = 0, Optional ByRef b As Integer = 0)
End Sub

Erroneous output

public void S(int a = 0, [Optional, DefaultParameterValue(0)] ref int b) //CS1737: Optional parameters must appear after all required parameters
{
}

Expected output

Using the OptionalAttribute instead on preceding parameters fixes the issue.

public void S([Optional, DefaultParameterValue(0)] int a, [Optional, DefaultParameterValue(0)] ref int b)
{
}

Details

GrahamTheCoder commented 10 months ago

Ah, yes, makes sense. There are some cases where an attribute can't be used such as a vb date I think but should generally work Edit: just spotted https://github.com/icsharpcode/CodeConverter/issues/1056