Skip to content

VB -> C#: Multi line strings #1173

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

Open
wizzardmr42 opened this issue Apr 2, 2025 · 4 comments
Open

VB -> C#: Multi line strings #1173

wizzardmr42 opened this issue Apr 2, 2025 · 4 comments
Labels
compilation error A bug where the converted output won't compile good first issue VB -> C# Specific to VB -> C# conversion

Comments

@wizzardmr42
Copy link

wizzardmr42 commented Apr 2, 2025

VB.Net input code

            Dim tmp = "
"

Erroneous output

string tmp = "
";

Expected output

var tmp = @"
";

Details

VS extension 9.2.7.0

@wizzardmr42 wizzardmr42 added the VB -> C# Specific to VB -> C# conversion label Apr 2, 2025
@GrahamTheCoder
Copy link
Member

Can you explain further why the current output causes you a problem?
It's valid csharp and most accurately reflects the input as far as I can see.
@ indicates a verbatim string, so your suggested output would literally contain the backslash character rather than a newline.

@wizzardmr42
Copy link
Author

Sorry, it looks like I went too far trying to get a minimal sample. I wasn't familiar with verbatim strings. I'll have to try it again and see what was causing the compiler errors. It might have been something to do with string interpolation.

@wizzardmr42
Copy link
Author

I've edited the original issue post

@GrahamTheCoder
Copy link
Member

Thanks that makes sense, should be easy to test and fix here if anyone wants to have a go:

internal static string GetQuotedStringTextForUser(string textForUser, string valueTextForCompiler)
{
var sourceUnquotedTextForUser = Unquote(textForUser);
var worthBeingAVerbatimString = IsWorthBeingAVerbatimString(valueTextForCompiler);
var destQuotedTextForUser =
$"\"{EscapeQuotes(sourceUnquotedTextForUser, valueTextForCompiler, worthBeingAVerbatimString)}\"";
return worthBeingAVerbatimString ? "@" + destQuotedTextForUser : destQuotedTextForUser;
}

@GrahamTheCoder GrahamTheCoder added compilation error A bug where the converted output won't compile good first issue labels Apr 3, 2025
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 good first issue VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

2 participants