Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested Class .GetType()

I noticed something curious when messing around with nested classes and outputting the name of the type to a console window. I was wondering if someone could explain it a bit for me. When calling GetType() on the main class, it returns what I would expect, which was the name of the class after the relevant namespaces. i.e. Namespace.Namespace.Classname

However, when I call a function from within the enclosing class to return the type of the nested class I get the value returned as this:

Namespace.Namespace.ClassNameEnclosing + ClassNameNested.

Why is it not simply returned as dot notation. Why the + symbol? I am just curious as to what is going on in the background that causes this notation.

like image 542
CSharpened Avatar asked Feb 02 '12 10:02

CSharpened


1 Answers

Dots are used to denote namespaces. The nested class is still in the same namespace, it's just nested within a class.

I can't tell offhand (from a brief study of ECMA-335) whether an unqualified type name which included a dot would actually be valid in IL; I suspect it would, but it would make all kinds of diagnostics harder to read.

like image 146
Jon Skeet Avatar answered Sep 20 '22 03:09

Jon Skeet