DeclaringSyntaxReferences 之间有什么区别?属性(property)和Locations ISyntax 中的属性(property)界面?
最佳答案
答案的线索在 <remarks>
中评论区:
The syntax node(s) that declared the symbol. If the symbol was declared in metadata or was implicitly declared, returns an empty read-only array.
这意味着 Locations
还返回元数据引用声明和隐式声明的位置。您可以在 LocationsTests.cs 中看到这方面的证据文件:
var c = s.GetTypeMembers("C", 0).Single() as NamedTypeSymbol;
var obj = c.BaseType;
Assert.Equal("MetadataFile(CommonLanguageRuntimeLibrary)", obj.Locations[0].ToString());
哪里c
是class C
在:
namespace N.S{class C{int F; void M(int P}{}}
所以 obj
是System.Object
.这是有道理的,因为您没有任何实际的源代码,因此在编译中没有定义 System.Object
的语法 .
关于c# - ISymbol.DeclaringSyntaxReferences 和 ISymbol.Locations 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38775807/