Nested class .GetType ()

I noticed something curious when I was fiddling with nested classes and displaying the type name in the console window. I was wondering if anyone could explain this to me. When calling GetType() in the main class, it returns what I would expect, it was the name of the class after the corresponding namespaces. those. Namespace.Namespace.Classname

However, when I call a function from the built-in class to return the type of the nested class, I get the return value:

 Namespace.Namespace.ClassNameEnclosing + ClassNameNested. 

Why is this not just coming back as a dotted notation. Why is the symbol +? I'm just wondering what happens in the background, what causes this designation.

+7
source share
2 answers

Dots are used to denote namespaces. The nested class is still in the same namespace, it is simply nested in the class.

I can’t say out of the blue (from a brief study of ECMA-335) whether there was an unconditional type name that included a period that would really be valid in IL; I suspect it would be, but it would make all kinds of diagnostics more difficult to read.

+5
source

Reflection is language independent.

The dot notation ( Namespace.Namespace.OuterClassName.InnerClassName ) is specific to C #. Reflection should work for every language you can use to compile to IL. Also, how can you be sure that OuterClassName is not just part of the namespace without exploring the other properties of the Type class?

You ask why this is not just coming back as a dotted notation? You might also ask, β€œWhy doesn't this just return as IronPython notation,” or IronLisp notation, or L # notation, or BOo notation, or ...

Learn the notation used in reflection, and you can use it to analyze code written in any language.

+1
source

All Articles