Skip to content
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

VB -> C# handle > operators for strings #396

Closed
v1nce opened this issue Oct 23, 2019 · 5 comments · Fixed by #576
Closed

VB -> C# handle > operators for strings #396

v1nce opened this issue Oct 23, 2019 · 5 comments · Fixed by #576
Labels
compilation error A bug where the converted output won't compile help wanted VB -> C# Specific to VB -> C# conversion

Comments

@v1nce
Copy link

v1nce commented Oct 23, 2019

It would be awesome if code converter could handle [string] >[string] for us

Input code

mystring > ""

Erroneous output

mystring > ""

Expected output

String.compare(mystring , "") > 0

Details

  • Product in use:VS extension
  • Version in use: 7.2.0.0
@GrahamTheCoder
Copy link
Member

GrahamTheCoder commented Oct 24, 2019 via email

@v1nce
Copy link
Author

v1nce commented Oct 24, 2019

I don't use them myself, this is legacy code.

It looks like it's more complicated than I expected.

The "right" thing to do (for strings) could be to use

using Microsoft.VisualBasic.CompilerServices;
Operators.CompareString("Peter", "Davis", %comparisonOption%)

With comparisonOption being an "external" var defined in the *.vbproj (see image attached)
Microsoft Visual Studio

In VB comparisons operators are also valid between string, int, float...
https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/comparison-operators?view=netframework-4.8

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/option-compare-statement#when-an-option-compare-statement-is-not-present

@GrahamTheCoder
Copy link
Member

GrahamTheCoder commented Oct 24, 2019 via email

@GrahamTheCoder GrahamTheCoder added compilation error A bug where the converted output won't compile help wanted VB -> C# Specific to VB -> C# conversion labels Oct 24, 2019
@GrahamTheCoder
Copy link
Member

This is a handy place to start for checking the implementation: https://github.com/dotnet/roslyn/blob/master/src/Compilers/VisualBasic/Portable/Binding/Binder_Operators.vb#L130
I'm hoping the symbol/operation API will allow me to detect whether an operator is user defined without doing the heavy lifting myself.

The comment just above the linked line makes a good point about a possible improvement to VisitBinaryExpression to avoid stackoverflows (I've seen at least one before from this effect):

Some tools, such as ASP .NET, generate expressions containing thousands
of string concatenations. For this reason, for string concatenations,
avoid the usual recursion along the left side of the parse. Also, attempt
to flatten whole sequences of string literal concatenations to avoid
allocating space for intermediate results.

@GrahamTheCoder
Copy link
Member

The implementation that binds to the VB methods is here:
https://github.com/dotnet/roslyn/blob/master/src/Compilers/VisualBasic/Portable/Lowering/LocalRewriter/LocalRewriter_BinaryOperators.vb#L233-L464

Note that it doesn't rewrite the method if it's within an expression lambda (as we've already got wrong for equality - see #316)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compilation error A bug where the converted output won't compile help wanted VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants