ISymbol.DeclaringSyntaxReferences 和 ISymbol.Locations 之间的区别 [英] Difference between ISymbol.DeclaringSyntaxReferences and ISymbol.Locations

查看:38
本文介绍了ISymbol.DeclaringSyntaxReferences 和 ISymbol.Locations 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DeclaringSyntaxReferences 之间有什么区别Locations 属性在 ISyntax 接口?

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

推荐答案

答案的线索在评论区:

声明符号的语法节点.如果符号在元数据中声明或隐式声明,则返回一个空的只读数组.

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 文件:

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());

其中 cclass C 在:

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

所以 objSystem.Object.这是有道理的,因为您没有任何实际的源代码,因此在编译中没有定义 System.Object语法.

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.

这篇关于ISymbol.DeclaringSyntaxReferences 和 ISymbol.Locations 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆