Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Roslyn 中是否有任何函数,通过它我可以将我的字符串解析为 MethodDeclarationSyntax?
我有一个包含方法声明的文件,所以我正在将该文件内容读取到字符串,现在我想从该字符串创建一个方法。有什么建议么?
一种选择是将您的字符串解析为“C# Script”,这是一个允许顶级方法声明的 C# 实验版本。正在做:
var tree = SyntaxTree.ParseText("void Foo() {}", options: new ParseOptions(kind: SourceCodeKind.Script));
为您提供包含CompilationUnitSyntax单个方法声明的有效语法树。
CompilationUnitSyntax