使用类型同义词导致 CS0246 找不到类型或名称空间名称...
using type synonym causes CS0246 The type or namespace name ... could not be found
我用短同义词命名了一个类型。
在下一行中,我尝试通过它的这个新短名称以某种方式使用这种类型(无关紧要):
using A = SomeTypeName;
using B = A;
但是在第 2 行中,编译器没有看到名称 "A" 并生成错误(见标题)。
为什么?
ECMA-334 9.4.1 使用别名指令 说:
The order in which using-alias-directives are written has no
significance, and resolution of the namespace-or-type-name referenced
by a using-alias-directive is not affected by the
using-alias-directive itself or by other using-directives in the
immediately containing compilation unit or namespace body. In other
words, the namespace-or-type-name of a using-alias-directive is
resolved as if the immediately containing compilation unit or
namespace body had no using-directives. A using-alias-directive may
however be affected by extern-alias-directives in the immediately
containing compilation unit or namespace body.
我用短同义词命名了一个类型。 在下一行中,我尝试通过它的这个新短名称以某种方式使用这种类型(无关紧要):
using A = SomeTypeName;
using B = A;
但是在第 2 行中,编译器没有看到名称 "A" 并生成错误(见标题)。 为什么?
ECMA-334 9.4.1 使用别名指令 说:
The order in which using-alias-directives are written has no significance, and resolution of the namespace-or-type-name referenced by a using-alias-directive is not affected by the using-alias-directive itself or by other using-directives in the immediately containing compilation unit or namespace body. In other words, the namespace-or-type-name of a using-alias-directive is resolved as if the immediately containing compilation unit or namespace body had no using-directives. A using-alias-directive may however be affected by extern-alias-directives in the immediately containing compilation unit or namespace body.