到目前为止,我已经能够在method.body中找到Console.WriteLine(“Hello World”)语句。但我想从WriteLine(“Hello World”)收集“Hello World”字符串;声明。我怎么能这样做?我的代码:
MethodDeclarationSyntax method = syntaxTree.GetRoot()
.DescendantNodes()
.OfType<MethodDeclarationSyntax>()
.First();
BlockSyntax statement = method.Body;
ControlFlowAnalysis controlFlow = semanticModel.AnalyzeControlFlow(statement);
StatementSyntax state = statement.Statements.First();
Console.WriteLine(state.ToString());
Console.ReadLine();