paul1956 / CSharpToVB

New version of CSharpToVB converter
MIT License
26 stars 9 forks source link

For Each and Tuple Deconstruction #59

Closed DualBrain closed 3 years ago

DualBrain commented 3 years ago

Given the following original code:

    static IEnumerable<(string, string)> SourceFilesFromMustachePaths(IEnumerable<(string, string, string)> pathsData)
    {
        foreach ((string name, string template, string hash) in pathsData)
        {
            yield return (name, SourceFileFromMustachePath(name, template, hash));
        }
    }

When manually converted, looks something like:

Private Shared Iterator Function SourceFilesFromMustachePaths(pathsData As IEnumerable(Of (String, String, String))) As IEnumerable(Of (String, String))
  For Each entry In pathsData
    Yield (entry.Item1, SourceFileFromMustachePath(entry.Item1, entry.Item2, entry.Item3))
  Next
End Function

Or with a little more "cleanup":

Private Shared Iterator Function SourceFilesFromMustachePaths(pathsData As IEnumerable(Of (Name As String, Template As String, Hash As String))) As IEnumerable(Of (Name As String, Code As String))
  For Each entry In pathsData
    Yield (entry.Name, SourceFileFromMustachePath(entry.Name, entry.Template, entry.Hash))
  Next
End Function

And thinking about this, it could also look like (not pretty, but works):

Private Shared Iterator Function SourceFilesFromMustachePaths(pathsData As IEnumerable(Of (String, String, String))) As IEnumerable(Of (String, String))
  For Each tupleTemp In pathsData
    Dim name = tupleTemp.Item1, template = tupleTemp.Item2, hash = tupleTemp.Item3        
    Yield (name, SourceFileFromMustachePath(name, template, hash))
  Next
End Function

Hopefully this provides some food for thought in coming up with a solution to hopefully implement the conversion.

paul1956 commented 3 years ago

@DualBrain I am missing something where did you get "Entry"?

paul1956 commented 3 years ago

I implemented your last example in 5.0.0.20

DualBrain commented 3 years ago

I am missing something where did you get "Entry"?

It was hand converted; but I see that you probably figured that out. The code translation (result) looks great!