I have a case where I need to convert C # - to a VB.NET project. (I want to automate this, so I cannot use an online tool or something like that)
There is a sample visual studio extension, "Paste as C # / VB," which seemed to be able to do this.
I tried to convert this class:
namespace TestApplication
{
class Class1
{
public void Lorem()
{
}
}
}
But it ended up:
Namespace TestApplication
Class Class1
''' <summary> Lorem </summary> Public Sub Lorem()
End Sub
End Class
End Namespace
This happens not only when providing comments on XML documentation, but sometimes also when inheriting other classes, etc.
Here is the code that handles the conversion of the sample:
csharpToVisualBasicConverter.Convert returns an instance of SyntaxNode.
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());
}
convert, , SyntaxNode SyntaxNode.ToFullString() ..
- ?