Roslyn Convert C to VB

0 votes

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?

Dec 12, 2022 in C# by Roshan
• 300 points
518 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 C#

0 votes
0 answers

How Convert VB Project to C#

I have a VB project that has ...READ MORE

Jun 11, 2022 in C# by jyoti
• 1,240 points
741 views
0 votes
0 answers

Convert async Task from c# to vb.net

I'm using a C# to VB.NET converter ...READ MORE

Dec 12, 2022 in C# by Roshan
• 300 points
1,614 views
0 votes
1 answer

What is the best C# to VB.net converter

Telerik has a solid SharpDevelop-based converter that ...READ MORE

answered May 30, 2022 in C# by rajiv
• 1,620 points
1,607 views
0 votes
1 answer

Convert VB.NET --> C# Projects

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

answered May 31, 2022 in C# by anonymous
784 views
0 votes
1 answer

How to convert JSON text into objects using C#

To make a class out of a ...READ MORE

answered Jun 13, 2022 in C# by krishna
• 2,820 points
573 views
0 votes
0 answers

Convert VB.NET --> C# Projects

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

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

Roslyn: Convert C# to VB

I have a project that I need ...READ MORE

Dec 9, 2022 in Android by Edureka
• 13,620 points
695 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,040 points
1,357 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
618 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
637 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