问题
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