Skip to content
New issue

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

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

Already on GitHub? # to your account

VB -> C#: With on a structure type doesn't work after conversion- #661

Closed
marcal opened this issue Oct 22, 2020 · 1 comment
Closed

VB -> C#: With on a structure type doesn't work after conversion- #661

marcal opened this issue Oct 22, 2020 · 1 comment
Labels
duplicate VB -> C# Specific to VB -> C# conversion

Comments

@marcal
Copy link

marcal commented Oct 22, 2020

Hello,

I have seen a problem with some with with when used with a structure type (Rectangle but probably point...).

Input code

Public Class Form1
    Private rec As Rectangle
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        With rec
            .Height = 100
            .Y = 100
            .Width = 100
            .X = 100
        End With
        MessageBox.Show(rec.Height)
' Should show 100

    End Sub
End Class

Erroneous output

public Form1()
        {
            InitializeComponent();
        }

        private Rectangle rec;

        private void Form1_Load(object sender, EventArgs e)
        {
            {
                var withBlock = rec;
                withBlock.Height = 100;
                withBlock.Y = 100;
                withBlock.Width = 100;
                withBlock.X = 100;
            }

            MessageBox.Show(rec.Height.ToString());
// Shows  0
        }
```-)

### Expected output
```C#
public Form1()
        {
            InitializeComponent();
        }

        private Rectangle rec;

        private void Form1_Load(object sender, EventArgs e)
        {
            {
                rec.Height = 100;
                rec.Y = 100;
                rec.Width = 100;
                rec.X = 100;
            }

            MessageBox.Show(rec.Height.ToString());
        }

Details

Last plugin version.
When there is a struct type and a With, it is converted in a var Withblock but on a struct type you only change the copy of the structure not the original. (so changing the withBlock doesn't work.
The conversion is correct with a rectangle in the sub but not when it is declared in the form (private)

  • Version in use: 8.2.0.0
    I guess it should be the same for point...

Marc

@marcal marcal added the VB -> C# Specific to VB -> C# conversion label Oct 22, 2020
@GrahamTheCoder
Copy link
Member

Thanks, definitely worth some investigation. I'll close this as a duplicate of #634 and track progress there

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
duplicate VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

2 participants