Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VB -> C#: ReDim Preserve of array property #1156

Open
gaschd opened this issue Nov 10, 2024 · 0 comments
Open

VB -> C#: ReDim Preserve of array property #1156

gaschd opened this issue Nov 10, 2024 · 0 comments
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@gaschd
Copy link
Contributor

gaschd commented Nov 10, 2024

Converting ReDim Preserve on an array property throws
CS0206: A property or indexer may not be passed as an out or ref parameter
while Array.Resize is converted correctly by utilizing a local variable for this case.

VB.Net input code

Public Class TestClass
    Public Property NumArray1 As Integer()

    Public Sub New()
        Array.Resize(NumArray1, 3)

        ReDim Preserve NumArray1(4)
    End Sub
End Class

Erroneous output

using System;
              
public partial class TestClass
{
public int[] NumArray1 { get; set; }

public TestClass()
{
    var argarray = NumArray1;
    Array.Resize(ref argarray, 3);
    NumArray1 = argarray;

    Array.Resize(ref this.NumArray1, 5);
}

Expected output

using System;

public partial class TestClass
{
    public int[] NumArray1 { get; set; }    

    public TestClass()
    {
        var argarr = NumArray1;
        Array.Resize(ref argarr, 3);
        NumArray1 = argarr;

        var argarr1 = NumArray1;
        Array.Resize(ref argarr1, 5);
        NumArray1 = argarr1;
    }
}

Details

  • Product in use: VS extension
  • Version in use: master abea701
@gaschd gaschd added the VB -> C# Specific to VB -> C# conversion label Nov 10, 2024
gaschd added a commit to gaschd/CodeConverter that referenced this issue Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

1 participant