Difference between ISymbol.DeclaringSyntaxReferences and ISymbol.Locations

坚强是说给别人听的谎言 提交于 2019-12-10 20:17:40

问题


What is the difference between the DeclaringSyntaxReferences property and Locations property in the ISyntax interface?


回答1:


The clue to the answer is in the <remarks> comment section:

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.

Which means, that Locations also returns metadata reference declarations and implicitly declared locations. You can see evidence for that in the LocationsTests.cs file:

var c = s.GetTypeMembers("C", 0).Single() as NamedTypeSymbol;
var obj = c.BaseType;
Assert.Equal("MetadataFile(CommonLanguageRuntimeLibrary)", obj.Locations[0].ToString());

where c is the class C in:

namespace N.S{class C{int F; void M(int P}{}}

so obj is System.Object. This makes sense, because you don't have any actual source code, and thus syntax, in the compilation, that would define System.Object.



来源:https://stackoverflow.com/questions/38775807/difference-between-isymbol-declaringsyntaxreferences-and-isymbol-locations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!