有一个“”x2B;”在班级名称中?

发布于 2024-08-25 11:16:45 字数 122 浏览 8 评论 0原文

类名:MyAssembly.MyClass+MyOtherClass

问题显然是用+作为分隔符,而不是传统的点号,其作用,又去找官方文档,看看其他分隔符是否存在。

Class name: MyAssembly.MyClass+MyOtherClass

The problem is obviously the + as separator, instead of traditionnal dot, its function, and to find official documentation to see if others separators exist.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

榕城若虚 2024-09-01 11:16:45

这就是嵌套类型的表示方式。例如:

namespace Foo
{
    class Outer
    {
        class Nested {}
    }
}

将在编译的代码中创建一个全名为 Foo.Outer+Nested 的类型。 (例如,这就是 typeof(Outer.Nested).FullName 会返回的内容。)

我不清楚这是否是指定的行为,或者只是 Microsoft C# 的行为编译器选择使用;这是一个“难以形容”的名称,因为您无法在普通 C# 中显式声明带有 + 的类,因此编译器知道它不会与其他任何内容发生冲突。据我所知,C# 3 规范的第 10.3.8 节并未规定编译名称。

编辑:我刚刚看到 Type.AssemblyQualifiedName< /code>指定“+”用于嵌套类型名称之前...但仍不清楚这是否实际上是必需的或只是常规的。

That's just the way that a nested type is represented. So for example:

namespace Foo
{
    class Outer
    {
        class Nested {}
    }
}

will create a type with a full name of Foo.Outer+Nested in the compiled code. (So that's what typeof(Outer.Nested).FullName would return, for example.)

It's not clear to me whether this is specified behaviour, or just what the Microsoft C# compiler chooses to use; it's an "unspeakable" name in that you couldn't explicitly declare a class with a + in it in normal C#, so the compiler knows it won't clash with anything else. Section 10.3.8 of the C# 3 spec doesn't dictate the compiled name as far as I can see.

EDIT: I've just seen that Type.AssemblyQualifiedName specifies that "+" is used to precede a nested type name... but it's still not clear whether or not that's actually required or just conventional.

格子衫的從容 2024-09-01 11:16:45

这就是编译器在元数据中使用的内容来表示嵌套类。

class A { class B {} }

会被视为

class A+B

在元数据中

This is what the compiler uses in the metadata to represent a nested class.

i.e.

class A { class B {} }

would be seen as

class A+B

in the metadata

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文