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

Conversion for FixedStatement not implemented #1101

Open banyanno opened 4 months ago

banyanno commented 4 months ago

Input code

In unsafe context

public class CSharpClass
{
    public static void Main(){
        byte[] bytes = [1, 2, 3];
        fixed (byte* bufferPtr = bytes)
        {
            Console.WriteLine($"The address of the first array element: {(long)bufferPtr:X}.");
            Console.WriteLine($"The value of the first array element: {*bufferPtr}.");
        }
    }
}

Erroneous output

Public Class CSharpClass
    Public Shared Sub Main()

        If True Then
            Dim bytes As Byte() = _(1, 2, 3)
                        ''' Cannot convert FixedStatementSyntax, CONVERSION ERROR: Conversion for FixedStatement not implemented, please report this issue in 'fixed (byte* bufferPtr = by...' at character 91
''' 
''' 
''' Input:
'''     fixed (byte* bufferPtr = bytes)
'''     {
'''         Console.WriteLine($"The address of the first array element: {(long)bufferPtr:X}.");
'''         Console.WriteLine($"The value of the first array element: {*bufferPtr}.");
'''     }
''' 
''' 
        End If
    End Sub
End Class

Expected output

Imports System
Imports System.Runtime.InteropServices

Module Program
    Public Shared Sub Main()
        Dim bytes As Byte() = {1, 2, 3}

        Dim bufferHandle As GCHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned)
        Try
            Dim bufferPtr As IntPtr = bufferHandle.AddrOfPinnedObject()

            Console.WriteLine($"The address of the first array element: {bufferPtr.ToInt64():X}.")
            Console.WriteLine($"The value of the first array element: {Marshal.ReadByte(bufferPtr)}.")
        Finally
            bufferHandle.Free()
        End Try
    End Sub
End Module

Details

banyanno commented 4 months ago

CONVERSION ERROR: Conversion for FixedStatement not implemented, please report this issue in 'fixed (byte* bufferPtr = bu...' at character 18915

Sympatron commented 4 months ago

Please fill in the template correctly. It is unlikely that somebody is able to help you with so little information.

GrahamTheCoder commented 2 months ago

I've added my best guess at an input and expected output. A real example would help, though there are currently no contributors interested in implementing C#->VB features.