This is a migrated thread and some comments may be shown as answers.

Adding of EventHandler fails to convert properly C#->VB

1 Answer 63 Views
Code Converter
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Emanuel Varga
Top achievements
Rank 1
Emanuel Varga asked on 14 Oct 2010, 10:44 PM
Hello,

I was wondering what would be the downside of converting c# event assignments:
radButton1.Click += radButton1_Click;
to:
AddHandler radButton1.Click, AddressOf radButton1_click

But from VB to C# it is working just fine.... why?

Lately I've started to use the converter a lot, in order to provide solutions to people in both C# and vb, and because of the fact that the forum does not allow for uploading files I'm creating all the code in the examples by hand.

It's always a pain having to convert all of the event handlers by hand....

Best Regards,
Emanuel Varga

1 Answer, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 25 Oct 2010, 11:37 PM
This is actually a limit of the underlying NRefactory engine that powers the Code Converter. I suggest you request this support on the SharpDevelop forums: http://community.sharpdevelop.net/tags/nrefactory/default.aspx. You can further test the NRefactory engine using the simple converter provided by the core team: http://codeconverter.sharpdevelop.net/SnippetConverter.aspx.

I'm not entirely sure why the core engine can convert in one direction and not other. If I had to guess, I would say the language shortcut in C# is too ambiguous. That is, "+=" can be used for a number of things in C#, such as concatenating strings or incrementing values, so it's not "guaranteed" to be an event handler. In VB, though, the explicit AddHandler can more reliably be converted.

Hopefully a solution will be available soon to save you the manual steps! Sorry for the trouble.

-Todd
Tags
Code Converter
Asked by
Emanuel Varga
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Share this question
or