VB -> C#: Handleres of sub properties being untracked

Open
#1,273 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp
Domain
devtools

Research direction

Reproduce the issue with the supplied VB.NET input using the codeconv CLI and compare the generated C# with the expected output. Trace the converter's handling of VB Handles clauses for nested properties; done means Editor1.Properties.Click is subscribed in InitializeComponent alongside Editor1.Click.

Written by the indexing model from the issue text.

Description

VB -> C#
VB.Net input code

Imports System.ComponentModel

Public Class EditorProperties
    Public Event Click As EventHandler  ' Handles clause for this event is silently dropped
End Class

Public Class Editor
    Private ReadOnly _properties As New EditorProperties()

    ' DesignerSerializationVisibility.Content is what makes this property usable in a Handles clause
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
    Public ReadOnly Property Properties As EditorProperties
        Get
            Return _properties
        End Get
    End Property

    Public Event Click As EventHandler
End Class

<Microsoft.VisualBasic.CompilerServices.DesignerGenerated>
Partial Public Class Form1
    Private Sub InitializeComponent()
        Me.Editor1 = New Editor()
    End Sub
    Friend WithEvents Editor1 As Editor
End Class

Partial Public Class Form1
    Private Sub Editor1_Properties_Click(sender As Object, e As EventArgs) Handles Editor1.Properties.Click
    End Sub

    Private Sub Editor1_Click(sender As Object, e As EventArgs) Handles Editor1.Click
    End Sub
End Class

Erroneous output

public partial class Form1
{
    public Form1()
    {
        InitializeComponent();
    }
    private void InitializeComponent()
    {
        Editor1 = new Editor();
        Editor1.Click += new EventHandler(Editor1_Click);
    }
    internal Editor Editor1;
}

public partial class Form1
{
    private void Editor1_Properties_Click(object sender, EventArgs e) // This handler lost tracker
    {
    }

    private void Editor1_Click(object sender, EventArgs e)
    {
    }
}

Expected output

public partial class Form1
{
    public Form1()
    {
        InitializeComponent();
    }
    private void InitializeComponent()
    {
        Editor1 = new Editor();
        Editor1.Click += new EventHandler(Editor1_Click);
        Editor1.Properties.Click += new EventHandler(Editor1_Properties_Click); // Expected
    }
    internal Editor Editor1;
}

Details
  • Product in use: codeconv CLI global tool (icsharpcode.codeconverter.codeconv)
  • Version in use: 10.0.1.923
Dominant language
C#
Stars
913
Forks
244
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from icsharpcode/CodeConverter

All issues in icsharpcode/CodeConverter

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.