0

i want to analyze vb code with a parse like roselyn or mcs, but i want to do it with c sharp but the code i want to analyze is in vb code.

I have seen that in both frameworks, you can pass the code and gives you the syntax tree, but for example if your writting it in c sharp, it can parser visual basic code?

SyntaxTree tree = SyntaxTree.ParseCompilationUnit(@"Imports System
Imports System.Collections
Imports System.Linq
Imports System.Text

Namespace HelloWorld

    Module Program
       
        Sub Main(args As String())
      
            Console.WriteLine(“Hello, World!”)
     
        End Sub
  
     End Module

End Namespace");
var root = (CompilationUnitSyntax)tree.GetRoot();

My question is if the can be done with the mcs from mono or with microsoft roslyn?

4

1 回答 1

2

是的,你可以这么做。您只需要使用命名空间中的类型Roslyn.Compilers.VisualBasic(在具有相同名称的程序集中)而不是来自Roslyn.Compilers.CSharp.

于 2013-08-13T08:36:35.793 回答