-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Options for migration of string comparisons (helper method?) #1034
Comments
Hi, thanks for getting in touch. There aren't currently any options for this, but I understand and agree with the sentiment - the output looks dreadful when sprinkled all over the place especially. In general, I've tried to avoid helper methods where possible. CodeConverter/CodeConverter/CSharp/VisualBasicEqualityComparison.cs Lines 237 to 248 in 3c98bfe
Also see: https://github.com/icsharpcode/CodeConverter/blob/3c98bfebd380c6669c0d3f0ccdffc121767aa5ed/.github/CONTRIBUTING.md#how-to-get-started-changing-code I'm open to a PR that adds an option to the options dialog to customise this case to what you think is best too. Here are a couple of examples that add a helper method: CodeConverter/CodeConverter/VB/CSharpHelperMethodDefinition.CSharpHelperMethodDefinition.cs Line 53 in 3c98bfe
I should mention that if you just want the easiest no-code fix for your case, you can probably just regex find/replace the output to call a method, then add that method manually somewhere |
Thank you Graham, I have a few other things to close off so will take some time to get onto this in a serious way, but it looks perfectly doable, and when done I will communicate back here with what I came up with. Thanks for the pointers also. I'm sure I will have some other contributions or suggestions after converting this monster project ! |
I've been trying to do some fiddling in advance of taking this seriously, by putting a break point in the source code. But when running from "codeconv" it comes up with this error:
It compiles fine from the vsix and of course from vb itself. I've tried cleaning etc, but can't delete the obj/bin folders because they contain reference dlls. |
Seems like a known build issue separate from the converter: https://stackoverflow.com/questions/52182158/vs-15-8-2-broke-build-tools-missing-runtimeidentifier If you want to sidestep the whole mess, you could try running the Vsix startup project instead, which should be able to start another instance of visual studio with the converter running in debug mode. Or, even more likely to "just work", copy an existing test, put in a snippet of the code you want to look at, and run that in debug mode. |
I don't know if this helps, but I just accidentally came across a decompilation of my code into C# done by visual studio. Basically I forgot to build one of the components so it gave me a c# decompilation of the previous build of the VB on the fly, which I've never seen before. Anyway, this the code it generated is: If msTransformDesc = "Some Value" Then
Throw New Security.SecurityException("Permission denied")
End If if (Operators.CompareString(msTransformDesc, "Some Value", TextCompare: true) == 0)
{
throw new SecurityException("Permission denied");
} So perhaps I still haven't got back to this, but thought the above might help. Edit: See here: https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.compilerservices.operators.comparestring?view=net-7.0 So I think Operators.CompareString is a "special" thing recognised by the compiler, and is not available for coding. |
Thanks for this issue |
Perhaps this should not be an issue or a feature request but I think it's worthy of discussion, and we can always delete later if needed.
I'm about to Migrate perhaps 50k to 100k lines of code from VB to C#. Almost all of it has Option Compare Text.
Now when we migrate, code like this
It gets converted to this:
I'm sure I'm not the only one who doesn't want to live with that kind of code going forward, especially in a large project.
Ideally I would like improve the syntactic elegance using something like an Extension method
Then the migrated c# would be
I would have liked to overload the string == operator but that doesn't sound possible.
So, before I start digging in the CodeConverter source code for how to implement this, are there any other options or ways to influence the conversion as above, and does anyone else feel that there would be value in changing the code if appropriate for something like the above ?
The text was updated successfully, but these errors were encountered: