C# 语法 "base"

C# grammar "base"

我正在研究 C# 5.0 的语法,不太了解 "base" 的用法。在参考手册中,有一个概念"base access"定义为:

base-access:
    base   .   identifier
    base   [   expression-list   ]

其中base是关键字,看来只有这种情况。但是,我遇到了 C# 输入,例如

base.WithAdditionalDiagnostics<TNode>(node, diagnostics);

谁能指出这个语句指的是哪个语法规则?由于 'base' 似乎是一个普通的关键字,而不是上下文,我认为应该有针对这种情况的特定语法规则,并且 base 不能简单地是一个标识符。

我相信应该实际上是

base-access:
    base   .   identifier type-argument-list_opt
    base   [   expression-list   ]

... 这就像成员访问一样:

member-access:
    primary-expression   .   identifier   type-argument-list_opt
    predefined-type   .   identifier   type-argument-list_opt
    qualified-alias-member   .   identifier   type-argument-list_opt

换句话说,在表达式中

base.WithAdditionalDiagnostics<TNode>(node, diagnostics);

base.WithAdditionalDiagnostics<TNode>

base-access 部分 - 其余部分按照其他调用的方式进行解析,例如 x.WithAdditionalDiagnostics<TNode>(node, diagnostics).

来自 C# 5 规范的第 7.6.8 节:

At binding-time, base-access expressions of the form base.I and base[E] are evaluated exactly as if they were written ((B)this).I and ((B)this)[E], where B is the base class of the class or struct in which the construct occurs. Thus, base.I and base[E] correspond to this.I and this[E], except this is viewed as an instance of the base class.

如果没有额外的 type-argument-listopt,我认为您现有的表达式将无法解析。

这实际上在4th edition of the ECMA-334 specification中指定正确;我会将其作为 C# 规范的错误提出(并确保它不会在第 5 版中被破坏)。