Symbol.Name for compound namespace

Topics: APIs
May 15, 2014 at 3:08 PM
This code
                    namespace testing.Namespace1
                    { }
returns "Namespace1" for Symbol.Name.

I find this very unexpected. Is it possible to consider changing it?

I can think of no use for Namespace1 in this context. I think testing.Namespace1 would always be the desired outcome.

Perhaps I am missing something.
May 15, 2014 at 3:48 PM
Try using ToDisplayString() on the symbol instead. I believe under the covers, namespaces can really only have a normal identifier for a name. So when you say something like this:
namespace X.Y.Z
{
    // types
}
in C#, what you are really saying is this:
namespace X
{
    namespace Y
    {
        namespace Z
        {
            // types
        }
    }
}
And so the symbol you get for the namespace syntax is the symbol for the innermost namespace, which has a name of simply "Z". ToDisplayString() will give you the name as you would expect to see it in C#: "X.Y.Z"