CodeConverter
CodeConverter copied to clipboard
VB -> C#: XML literals should be XML-decoded
VB.Net input code
Dim v = <xml><</xml>.Value
Erroneous output
string v = new XElement("xml", "<").Value;
Expected output
string v = new XElement("xml", "<").Value;
Details
- Product in use: icsharpcode.github.io/CodeConverter
- Version in use: 9.0.4.0
-
Console.WriteLine(v)
outputs<
in VB.NET (expected result) and<
in C# (actual/erroneous result). - Prior to Visual Studio 2015, XML literals were the canonical workaround to create multi-line strings in VB.NET, so this pattern might (unfortunately) be common in old code.
Thanks, good context on likelihood there too. Looks reasonably straightforward to fix. Wherever the code that creates the xmlelement is just needs to xml decode first. In the case of a literal that can be done at conversion time but presumably needs a runtime call in other cases?
Unless I missed something, I think the issue only exist for literals, so I don't see (yet) where a runtime call would be needed. Dim x = <xml>a <%= "<" %></xml>
, for example, gets converted correctly.
Ah good, I wasn't sure what would happen if you referenced a variable containing "<" and stuff like that. I don't remember what is possible in vb's xml syntax