Having a "+" in the class name?

Class Name: MyAssembly.MyClass+MyOtherClass

The problem, obviously, is + as a separator instead of the traditional dot, its function, and looking for official documentation to see if other separators exist.

+8
c # class separator
Mar 14 '10 at 18:38
source share
2 answers

This is just a way of representing a nested type. For example:

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

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

It is not clear to me whether this is a given behavior or just a Microsoft C # compiler; it is an “inexpressible” name in which you cannot explicitly declare a class with + in it in normal C #, so the compiler knows that it will not encounter anything else. Section 10.3.8 of the C # 3 specification does not specify the compiled name, as far as I can see.

EDIT: I just saw that Type.AssemblyQualifiedName indicates that the "nested type" character is preceded by a "+" ... but it is still unclear whether this is really required or just conditionally.

+13
Mar 14 '10 at 18:41
source share

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

i.e.

 class A { class B {} } 

will be considered as

 class A+B 

in metadata

+10
Mar 14 '10 at 18:40
source share



All Articles