Roslyn Convert C to VB

0 votes

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?


 

Dec 9, 2022 in Android by Edureka
• 13,580 points
392 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Android

0 votes
0 answers

Convert VB.NET --> C# Projects

Can someone suggest a suitable program that ...READ MORE

Dec 9, 2022 in Android by Edureka
• 13,580 points
150 views
0 votes
0 answers

How do I turn a C# object into a JSON string in .NET?

I have classes like these: class MyDate { ...READ MORE

Sep 20, 2022 in Android by Edureka
• 13,580 points
186 views
0 votes
0 answers

What are the differences between C, C# and C++ in terms of real-world applications?

As I stated in an earlier article, ...READ MORE

Sep 20, 2022 in Android by Edureka
• 13,580 points
180 views
0 votes
0 answers

What is the difference between C# and .NET?

May I know what is the difference ...READ MORE

Sep 20, 2022 in Android by Edureka
• 13,580 points
192 views
0 votes
0 answers

"unable to locate adb" using Android Studio

I've been attempting to test my software ...READ MORE

Sep 21, 2022 in Android by Edureka
• 13,580 points
300 views
0 votes
0 answers

How to make grid view scroll horizontally not vertically in android?

I use a flexible Grid View. means ...READ MORE

Sep 21, 2022 in Android by Edureka
• 13,580 points
206 views
0 votes
0 answers

Roslyn: Convert C# to VB

I have a situation where I need ...READ MORE

Dec 12, 2022 in C# by Roshan
• 300 points
227 views
0 votes
0 answers

Adding the CANONICAL tag to my page for SEO through code behind?

I am using ASP.NET with MasterPages. Thus ...READ MORE

Mar 3, 2022 in Digital Marketing by Kichu
• 19,050 points
1,004 views
0 votes
0 answers

Compiling New C# Versions (C# 7.0 Higher) From The Command Line

When I use Microsoft's Visual C# Compiler ...READ MORE

May 27, 2022 in Others by pranav
• 2,590 points
443 views
0 votes
1 answer

Convert VB.NET --> C# Projects

You may decompile whole Assemblies into Visual ...READ MORE

answered May 30, 2022 in C# by rajiv
• 1,620 points
252 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP