Skip to content

Commit ec70e8b

Browse files
Switch to verbatim style escaping since all VB strings are verbatim
1 parent 8ee309e commit ec70e8b

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ All notable changes to the code converter will be documented here.
88
### C# -> VB
99
* Improve event identifier conversion
1010

11+
### VB -> C#
12+
* Improve conversion of interpolated strings (format, alignment, escaping)
13+
1114
# 6.5.0 03/03/2019
1215
* Avoid fatal error converting a project in a solution containing a website project (#243)
1316
* Improve best-effort conversion in the presence of errors

ICSharpCode.CodeConverter/VB/NodesVisitor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,13 @@ public override VisualBasicSyntaxNode VisitInterpolatedStringExpression(CSS.Inte
765765

766766
public override VisualBasicSyntaxNode VisitInterpolatedStringText(CSS.InterpolatedStringTextSyntax node)
767767
{
768-
return SyntaxFactory.InterpolatedStringText(SyntaxFactory.InterpolatedStringTextToken(node.TextToken.Text, node.TextToken.ValueText));
768+
return SyntaxFactory.InterpolatedStringText(SyntaxFactory.InterpolatedStringTextToken(ConvertUserText(node.TextToken), node.TextToken.ValueText));
769+
}
770+
771+
private static string ConvertUserText(SyntaxToken token)
772+
{
773+
if (CS.CSharpExtensions.IsVerbatimStringLiteral(token)) return token.Text;
774+
return token.ValueText.Replace("\"", "\"\"");
769775
}
770776

771777
public override VisualBasicSyntaxNode VisitInterpolation(CSS.InterpolationSyntax node)

Tests/VB/ExpressionTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public string StringInter(string t, DateTime dt)
3939
var a = $""pre{t} t"";
4040
var b = $""pre{t} \"" t"";
4141
var c = $@""pre{t} """"\ t"";
42+
var d = $""pre{t + ""\""""} \"" t"";
4243
var e = $@""pre{t + ""\""""} """"\ t"";
4344
var f = $""pre{{escapedBraces}}{dt,4:hh}"";
4445
return a + b + c + d + e + f;
@@ -53,6 +54,7 @@ Public Function StringInter(ByVal t As String, ByVal dt As DateTime) As String
5354
Dim a = $""pre{t} t""
5455
Dim b = $""pre{t} """" t""
5556
Dim c = $""pre{t} """"\ t""
57+
Dim d = $""pre{t & """"""""} """" t""
5658
Dim e = $""pre{t & """"""""} """"\ t""
5759
Dim f = $""pre{{escapedBraces}}{dt,4:hh}""
5860
Return a & b & c & d & e & f

0 commit comments

Comments
 (0)