I'm trying to get the full name of a namespace and convert it to a string.
Specifically, I have the namespace DevExpress.Xpf and I would like nameof2(DevExpress.Xpf) or some equivalent to return "DevExpress.Xpf", rather than the "Xpf" that nameof returns.
Currently, I am using $"{nameof(DevExpress)}.{nameof(DevExpress.Xpf)}" to achieve this end.
Is it possible to use reflection or some other feature of C# to get the full address of a namespace as a string?
The
Namespaceproperty of the Type object returns the fully qualified name of the namespace the type's declared in. So considering you have a class namedAin the namespaceDevExpress.Xpf, callingtypeof(A).Namespacewill return"DevExpress.Xpf".