VB -> C#: omitted parentheses cause conversion failures in delegates and custom-event raise accessors

Offen
#1,298 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 3 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
62/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
csharp, visualbasic
Bereich
compilers

Rechercherichtung

Start in the DeclarationNodeVisitor.VisitDelegateStatement path, where a null parameter list reaches SyntaxFactory.DelegateDeclaration; supply an empty C# parameter list as ordinary methods already do. Then check how a parameterless RaiseEvent accessor is converted so that the On<EventName>() method is not dropped. Done when both VB inputs with and without parentheses produce identical C# output, matching the expected delegate lines.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

VB -> C#
VB.Net input code
Public Delegate Sub Callback
Public Delegate Function Provider As Integer
Erroneous output
Cannot convert DelegateStatementSyntax, CONVERSION ERROR:
Value cannot be null. (Parameter 'parameterList')

at Microsoft.CodeAnalysis.CSharp.SyntaxFactory.DelegateDeclaration(...)
at ICSharpCode.CodeConverter.CSharp.DeclarationNodeVisitor.VisitDelegateStatement(...)
Expected output
public delegate void Callback();
public delegate int Provider();
Details
  • Product in use: VS extension, built locally from master.
  • Version in use: 10.0.1, local development build.
  • Did you see it working in a previous version, which? No.
  • Related to #1296: VB.NET permits parameterless delegate declarations without parentheses. Adding () after Callback or Provider avoids the failure, but both forms should convert identically.
  • The delegate visitor passes a null parameter list to the C# syntax factory when parentheses are omitted. Supplying an empty C# parameter list resolves the issue, consistent with the existing handling for ordinary methods and external declarations.
  • The same problem also affects a custom event's parameterless RaiseEvent accessor when declared without parentheses. In that case, the generated C# event is retained, but its corresponding On<EventName>() method is silently omitted.
Vorherrschende Sprache
C#
Sterne
917
Forks
243
Ø Merge
2 T. 15 Std.
Gemergte PRs (30 T.)
9

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus icsharpcode/CodeConverter

Alle Issues in icsharpcode/CodeConverter

Ähnliche Issues

Weitere Issues zu C#

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.