I have the case wherein I need to convert a C#- to a VB.NET project. (I want to automate this, so I cannot use an online tool or something similar)
There is a "Paste as C#/VB" sample visual studio extension which seemed to be able to do this.
I tried converting this class:
namespace TestApplication
{
class Class1
{
/// <summary>
/// Lorem
/// </summary>
public void Lorem()
{
}
}
}
But it ended up with this:
Namespace TestApplication
Class Class1
''' <summary> Lorem </summary> Public Sub Lorem()
End Sub
End Class
End Namespace
It does not only happen when XML-documentation comments are provided, but sometimes also when inheriting other classes etc.
Here's the code that handles the convertion of the sample:
csharpToVisualBasicConverter.Convert returns a SyntaxNode instance.
private void PasteAsVB()
{
var csharpCode = Clipboard.GetText(TextDataFormat.Text);
var tree = CS.SyntaxTree.ParseText(csharpCode);
var visualBasicCode = csharpToVisualBasicConverter.Convert(tree);
var start = wpfTextView.Selection.SelectedSpans.Min(s => s.Start).Position;
var end = wpfTextView.Selection.SelectedSpans.Max(s => s.End).Position;
var span = Span.FromBounds(start, end);
wpfTextView.TextBuffer.Replace(span, visualBasicCode.ToFullString());
}
As there is no exception when calling the convert method, I assume the method returns a valid SyntaxNode and the SyntaxNode.ToFullString() method or an encoding issue messes up the line breaks etc.
Did anybody experience this issue before and find a solution?