Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

problems on SnippetConverter

$
0
0

SnippetConverter wrongly convert C# to VB.NET in the following cases.


1. The type inference is used with for-loop or foreach-loop.

Example:

C#
foreach (var hoge in hoges) {...}

expected: (Option Infer On)
For Each hoge In hoges

Actually:
For Each hoge As var In hoges

** When the variable identifier is "year" or "day" in the for-loop or foreach-loop with the type inference, it operates in c# without trouble, but it is confused with Year() and Day() of a global function in VB.NET.

C#: (it work)
List<int> years = new List<int> { 2015, 2014, 2013 };
foreach (var year in years) {}

VB.NET: (It doesn't work)
Dim years As New List(Of Integer)() From { 2015, 2014, 2013 }
For Each year In years
    '.....
Next

If the converter had inferred the type: (it work. The variable name "year" is valid.)
Dim years As New List(Of Integer)() From {2015, 2014, 2013}
For Each year As Integer In years
    '.....
Next



2. increments

C#:
var i = 0;
var j = i++;

Converted:
Dim i = 0
Dim j = System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)

The correct one might be:
Dim j = System.Math.Min(System.Threading.Interlocked.Increment(i),i - 1)



3. The conversion of "for-loop" with a some condition  generate an endless loop.

Example:

C#:

for (var i = 0, l = hoge.Count; i < l; ++i)
{
 if (i == 3) {
  continue;
 }
 //do something
}

converted:
Dim i = 0, l = hoge.Count
While i < l
    If i = 3 Then
        Continue While '-- endless loop
    End If
    'do something
    i += 1
End While

expected:
Dim l = hoge.Count
For i As Integer = 0 To l - 1
    If i = 3 Then
        Continue For
    End If
    'do something
Next


Viewing all articles
Browse latest Browse all 1764

Trending Articles