-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Input
public class ClashingNames
{
private string ab;
void Test()
{
object aB = 5;
int Ab = 7;
}
void Test2(int ab)
{
object aB = 5;
int AB = 6;
string s = nameof(AB);
string s2 = nameof(ab);
}
}Expected output (from https://codeconverter.icsharpcode.net/)
Public Class x
Private ab As String
Private Sub Test()
Dim lAB As Object = 5
Dim Ab As Integer = 7
End Sub
Private Sub Test2(ByVal ab As Integer)
Dim lAB As Object = 5
Dim lAB1 As Integer = 6
Dim s As String = NameOf(lAB1)
Dim s2 As String = NameOf(ab)
End Sub
End ClassActual output
Option Compare Text
Option Explicit On
Option Infer Off
Option Strict On
Public Class x
Private _ab As String
Private Sub Test()
Dim aB As Object = 5
Dim Ab As Integer = 7
End Sub
Private Sub Test2(_ab As Integer)
Dim aB As Object = 5
Dim AB As Integer = 6
Dim s As String = NameOf(AB)
Dim s2 As String = NameOf(_ab)
End Sub
End ClassCompilation errors
error BC30288: Local variable 'Ab' is already declared in the current block.
error BC30288: Local variable 'AB' is already declared in the current block.
- Note: Obviously this is an extreme example. I did see the existing renaming code add "_Renamed" for one variable in another case I tried, so it does sometimes work.
Possible solution
After you forked from https://github.com/icsharpcode/CodeConverter/ I implemented a very robust and isolated way of renaming to avoid this issue. All you need to do is call this method on the project object just before you convert:
https://github.com/icsharpcode/CodeConverter/blob/master/CodeConverter/VB/ClashingMemberRenamer.cs#L21
It's not currently a public class, but I could make it public if you want to just use it via nuget rather than copying/converting?
Metadata
Metadata
Assignees
Labels
No labels