VB -> C#: Base constructor calls with noncanonical casing produce invalid C#

Open Beginner friendly
#1,301 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
tooling

Research direction

Start by locating the converter's recognition of VB.NET base-constructor initializers; the issue says it currently relies on a case-sensitive text comparison. Add regression coverage for mixed-case MyBase.new(value) and the parameterless MyBase.new form. Done means both produce a C# constructor initializer rather than a base.ctor call.

Written by the indexing model from the issue text.

Description

VB -> C#
VB.Net input code
Public Class DataSet1
    Inherits Global.System.Data.DataSet

    Public Sub New(value As String)
        MyBase.new(value)
    End Sub
End Class
Erroneous output

The base constructor call is emitted as a method call inside the constructor body:

public partial class DataSet1 : System.Data.DataSet
{
    public DataSet1(string value)
    {
        base.ctor(value);
    }
}

This produces compiler error CS0117 because DataSet does not contain a definition for ctor.

Expected output
public partial class DataSet1 : System.Data.DataSet
{
    public DataSet1(string value) : base(value)
    {
    }
}
Details
  • Product: Visual Studio extension, built locally from master.
  • Version: 10.0.1 (local development build).
  • Previous working version: No.

VB.NET is case-insensitive, so MyBase.New(value), MyBase.new(value), and MyBase.nEw(value) are equivalent. However, the converter uses a case-sensitive text comparison when recognizing the constructor initializer.

The same issue occurs with parameterless calls written without parentheses, such as MyBase.new.

A workaround is to use the canonical casing, MyBase.New.

Dominant language
C#
Stars
916
Forks
242
Avg merge
2d 15h
Merged PRs (30d)
9

Getting set up

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.