Search code examples
c#.netsystem.reflection

Is C# namespace separator (.) defined somewhere?


Full name separator in C# is period character (.). e.g. System.Console.Write.

Is this defined somewhere like Path.PathSeperator, or is it hard coded in .NET reflection classes as well?

(e.g. is Type.FullName implemented as Type.Namespace + "." + Type.Name assuming that it won't change?


Solution

  • Basically: the language specification. But actually, Type.FullName uses the BCL definitions, not the C# definitions - and interestingly they disagree. For example:

    namespace X {
        public class Y {
            public class Z {}
        }
    }
    

    To C#, Z is X.Y.Z; to the BCL it is X.Y+Z. The representation of generics changes too - with the BCL using back-ticks and numbers rather than angular brackets. I believe the BCL uses the CLI's format of types (which has a separate specification), but if you think about it: it is not required to do so (except for during reflection-emit).

    AFAIK, these separators are not exposed via anything like Path.PathSeparator - but is, as you say, hard coded into the Type etc classes.