C# -> VB: Better winforms conversion
See original GitHub issueI tackled similar issues for VB->C# in #540, #547, #550. Here are a few known bugs that occur in converting the standard winforms generated project. They’re roughly ordered from easier to harder.
Help wanted
As well as VB’s decreasing support from Microsoft and tool vendors, VB has a reputation as a starter/prototype language, but not being so good long term, robust projects. This means the number of people trying to convert a whole winforms project C#->VB is relatively small compared to converting snippets. On top of that, there are major differences in how VB structures winforms code, so there’s a large amount of work involved in getting this right.
For those reasons this hasn’t been a priority area, only occasionally improved, but if anyone’s interested in working on this area I’d be very happy to support them doing so.
There’s a May 2019 fork of this project which was itself converted to VB, and may well have fixes for some of these issues: https://github.com/icsharpcode/CodeConverter/issues/8#issuecomment-554673493 The author is very happy for them to be reintegrated where possible
Details
-
DefineConstants
in the project file needs to be converted between comma separated (VB) and semicolon separated (CSharp) - Everything is incorrectly qualified as
[global]
instead ofGlobal
- Add Option Infer to project file (to allow type inference)
- Convert MultiplyAssignmentStatement
- If one side of an & isn’t a string, call
?.ToString()
on it - If result of a division is type int, then use integer division
\
- Add default project imports into vbproj (e.g. System)
- Conversion is very slow for large files/projects due to the clashing renamer calling GetCsSymbolsDeclaredByMethod which calls LookupSymbols with a wide scope a lot of times
- Convert invoke method
- All parts of a partial class need the same modifier
- Ensure entry point
Sub Main
becomes public - Fix resource references (I think the fix is the same as it was VB->CS)
- CS -> VB Coalesce DefineDebug and DefineTrace into DefineConstants
- Use https://github.com/mashmawy/FastStyleTransfer as test case
- Generate something that works in the designer post-conversion https://github.com/icsharpcode/CodeConverter/issues/593
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (4 by maintainers)
It will be great at C# to VB, if remove AddHandler in Designer.vb
convert private objName As className to Friend WithEvents objName as clasName in form.vb file At end of each event function add Handles objName.EventHandlerName
Thanks.
Thanks. No need post the full list of errors unless they seem environment specific somehow - I can easily run it against the repo to get them. Let me know if there are any particular patterns you spot that haven’t been mentioned on linked issues