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#: Assignment operators of parameterized properties are not resolved #1157

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

Comments

@gaschd
Copy link
Contributor

gaschd commented Nov 10, 2024

Shorthand assignment operators like "+=" or "-=" are not resolved for parameterized properties.

VB.Net input code

Public Class TestClass
    Private _items As Integer() = New Integer() {1}
    Public Property Item(index As Integer) As Integer
        Get
            Return _items(index)
        End Get
        Set(value As Integer)
            _items(index) = value
        End Set
    End Property

    Private _strItems As String() = New String() {""Hello""}
    Public Property StrItem(index As Integer) As String
        Get
            Return _strItems(index)
        End Get
        Set(value As String)
            _strItems(index) = value
        End Set
    End Property

    Public Sub AllAssignmentOperators()
        Item(0) += 2        
        Item(0) *= 2         
        Item(0) ^= 2     
        Item(0) /= 2        
        Item(0) -= 2        
        Item(0) \= 2        
        Item(0) <<= 2
        Item(0) >>= 2
        StrItem(0) &= "" World""
    End Sub
End Class

Erroneous output

using System;
              
public partial class TestClass
{
    private int[] _items = new int[] { 1 };
    public int get_Item(int index)
    {
        return _items[index];
    }
    public void set_Item(int index, int value)
    {
        _items[index] = value;
    }
              
    private string[] _strItems = new string[] { ""Hello"" };
    public string get_StrItem(int index)
    {
        return _strItems[index];
    }
    public void set_StrItem(int index, string value)
    {
        _strItems[index] = value;
    }
              
    public void AllAssignmentOperators()
    {
        get_Item(0);
        get_Item(0);
        get_Item(0);
        get_Item(0);
        get_Item(0);
        get_Item(0);
        get_Item(0);
        get_Item(0);
        get_StrItem(0);
    }
}

Expected output

using System;
              
public partial class TestClass
{
    private int[] _items = new int[] { 1 };
    public int get_Item(int index)
    {
        return _items[index];
    }
    public void set_Item(int index, int value)
    {
        _items[index] = value;
    }
              
    private string[] _strItems = new string[] { ""Hello"" };
    public string get_StrItem(int index)
    {
        return _strItems[index];
    }
    public void set_StrItem(int index, string value)
    {
        _strItems[index] = value;
    }
              
    public void AllAssignmentOperators()
    {
        set_Item(0, get_Item(0) + 2);
        set_Item(0, get_Item(0) * 2);
        set_Item(0, (int)Math.Round(Math.Pow(get_Item(0), 2d)));
        set_Item(0, (int)Math.Round(get_Item(0) / 2d));
        set_Item(0, get_Item(0) - 2);
        set_Item(0, get_Item(0) / 2);
        set_Item(0, get_Item(0) << 2);
        set_Item(0, get_Item(0) >> 2);
        set_StrItem(0, get_StrItem(0) + "" World"");
    }
}

Details

  • Product in use: Test
  • Version in use: master abea701
@gaschd gaschd added the VB -> C# Specific to VB -> C# conversion label Nov 10, 2024
@gaschd gaschd changed the title VB -> C#: Assignment operators of indexed properties are not resolved VB -> C#: Assignment operators of parameterized properties are not resolved 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