I have a situation where I need to change a C# project into a VB.NET one. (Since I want to automate this, I can't use a programme that is available online or in a similar way.)
I tried changing this class:
namespace TestApplication
{
class Class1
{
/// <summary>
/// Lorem
/// </summary>
public void Lorem()
{
}
}
}
But ended up with this:
Namespace TestApplication
Class Class1
''' <summary> Lorem </summary> Public Sub Lorem()
End Sub
End Class
End Namespace
It occasionally occurs when inheriting from other classes as well as when XML-documentation comments are provided, etc.
The code that handles the conversion of the sample is provided here:
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());
}
I think the procedure returns a valid SyntaxNode because there isn't an exception when invoking the convert method. The line breaks, etc., are messed up by the SyntaxNode.ToFullString() method or an encoding problem.
Did anyone ever encountered something similar? Found any solutions?