问题描述
类名:MyAssembly.MyClass+MyOtherClass
问题很明显是+
作为分隔符,而不是传统的点,它的作用,要找官方文档看看有没有其他分隔符.
这就是嵌套类型的表示方式.例如:
命名空间 Foo{类外{类嵌套 {}}}
将在编译后的代码中创建一个全名为Foo.Outer+Nested
的类型.(例如,这就是 typeof(Outer.Nested).FullName
将返回的内容.)
我不清楚这是指定的行为,还是Microsoft C#编译器选择使用的行为;它是一个不可描述"的名称,因为您无法在普通 C# 中显式声明一个带有 + 的类,因此编译器知道它不会与其他任何东西发生冲突.据我所知,C# 3 规范的第 10.3.8 节并未规定编译后的名称.
我刚刚看到 Type.AssemblyQualifiedName
指定在嵌套类型名称之前使用+"...但仍不清楚这是否实际上是必需的或只是常规的.>
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.
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.
这篇关于有一个“+"在类名中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!