0
我会在方法体中的局部变量的符号,所以我用semanticModel.LookupSymbols.but结果有任何关于本地变量。 的代码是:为什么lookupsymbols api的结果不同?
var workspace = MSBuildWorkspace.Create();
var solution = workspace.OpenSolutionAsync(soluPath).Result;
var doc = solution.Projects[0].Documents[0];
var tree = doc.getSyntaxTreeASync().Result;
var semanticModel = doc.getSemanticModelASync().Result;
var symbols = semanticModel.LookupSymbols(tree.Length);
但如果我尝试另一种方式,结果有后援代码是:
var tree=SyntaxFactory.ParseSyntaxTree(source);
var compilation = VisualBasicCompilation.Create("m",new []{tree},new[]{mscorlib});
var semanticModel = compilation.GetSemanticModel(tree);
var symbols=model.LookupSymbols(tree.Length);
样品源:
Class C
End Class
Moudle Program
Private i As Integer = 0
Public Sub Main()
DIm j as Integer = 0 : j += i
End Sub
End Module
第一码输出:
C
Program
Public Sub Main()
第二个代码输出:
C
j
Microsoft
Private i As Integer
Program
Public Sub Main()
System
Windows
我的目标是局部变量“j”。 它们有什么区别? 感谢〜
有什么不同?你期望看到什么,你实际看到了什么? – JoshVarty
'tree.Length'不会有任何有用的符号。 – SLaks
如果tree.Length是无益的,参数应该是什么? –