I have a project that I need to convert from C# to VB.NET. (Since I want to automate this, I can't use a tool from the internet 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 conversion 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());
}
Since the convert method produces a legal SyntaxNode and there is no exception, I suppose that the line breaks and other formatting are messed up by the SyntaxNode.ToFullString() method or an encoding problem.
Did anyone ever encounter this problem and find a solution?