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

VB -> C#: A conversion error occurred when tracking a control using the event's "sender" parameter #1072

Closed FiveBushelsOfRice closed 8 months ago

FiveBushelsOfRice commented 8 months ago

VB.Net input code

We want to control the appearance of a set or class of combo boxes or respond to some behavior by writing a combo box click event

Private Sub TextBox_ComName_Click(sender As Object, e As EventArgs) Handles ComboBox_AreaName.Click
    sender.DroppedDown = True    
End Sub

The reason for using the event's "sender" parameter instead of the control name is that we want to control multiple controls at the same time with just one event

Erroneous output

private void ComboBox_AreaName_Click(object sender, EventArgs e)
{
    sender.DroppedDown = (object)true; 
}

Compiler Error CS1061:'type' does not contain a definition for 'name' and no accessible extension method 'name' accepting a first argument of type 'type' could be found (are you missing a using directive or an assembly reference?).

Expected output

will be referenced by multiple combo box click events

private void ComboBox_AreaName_Click(object sender, EventArgs e)
{
    ComboBox combo = (ComboBox)sender;
    combo.DroppedDown = true; 
}

Details

GrahamTheCoder commented 8 months ago

Thanks for the report, sorry I missed the notification. I'll close this as a duplicate of https://github.com/icsharpcode/CodeConverter/issues/1071 and give any updates there