-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
VB -> C#: Passing read-only property value by reference to a method #843
Comments
Thanks for the comprehensive bug report. The Telerik version is indeed an old one - before the general of passing properties by ref was tackled at all. |
The fix will probably need to go somewhere around here: https://github.com/icsharpcode/CodeConverter/pull/566/files#r817528266 |
No, I am not familiar with the code base, so I won't be working on this. Just wanted to let you know about the discrepancy. |
Fix released in 8.4.6. If you try it, let me know whether it's now working as expected, thanks! |
Thank you. I compared the output from 8.4.1 (which was the one I happened to have installed) with that of 8.4.6, and the CS0200 problem appears to have been fixed. |
Summary
When passing a read-only property value to a method, the converted code will copy the property value to a temp variable (ok), pass the temp variable to the method (ok), and then after return assign the temp variable value to the property value (fail). The last step is not seen when decompiling the code that was compiled from the original VB.NET source.
I am in the process of migrating a large VB.NET code base to C#. A lot of old methods and functions use the ByRef keyword for parameters that should have been passed by value - presumably because the original developers thought this was the right thing to do for performance reasons.
The right thing to do is to remove all of the ByRef keywords that can be removed and this will be done eventually, but right now the problem is that the ICSharpCode code converter extension (and its online sibling) generates C# code that cannot be compiled because of this issue.
I would like to see the ICSharpCode extension generate the same type of code as seen in the decompiler. Or at least a quick explanation why it behaves like it does. One might argue that the extension does the right thing by highlighting a problem, but the argument against that is that it is probably more correct to generate code that is as close to what the decompiled code looks like.
Details
VB.Net input code
Erroneous output
(Using Code Converter extension v8.4.1.0 as well as https://codeconverter.icsharpcode.net/)
Expected output
Details
Using:
Output from Code Converter extension is seen above.
Output from Telerik online code converter (supposedly based on ICSharpCode). No attempt to write the value back, but also does not use a temporary variable:
Output from dnSpy decompiler, when looking at the assembly compiled from the original code. Uses a temp variable like the ICSharpCode converter, but does not attempt to write the value back. This is the kind of code I expected from the extension:
The text was updated successfully, but these errors were encountered: