Reputation: 21037
I'm using the GetTypeInfo()
method to get the TypeInfo
of a class from an assembly.
Through that I'm trying to get the root namespace of that assembly (or is it called assembly namespace?). But I can't find a property in there that gives me that namespace. There is AssemblyQualifiedName
which is a string
that has the root namespace in it. But there are also a lot of other things in there like version number etc.
How can I get the root namespace of an assembly in .NET Core?
Upvotes: 3
Views: 2980
Reputation: 127573
Assemblies don't have namespaces themselves only the types within the assembly. The thing you could be thinking of is the "Assembly Name", that is often the same name as the "Default Namespace" which most types within the assembly will use.
Assembly assembly = //..
string name = assembly.GetName().Name;
The GetName()
returns a AssemblyName
object that contains the pieces that are used to build up the AssemblyQualifiedName
. This function is available in .Net Standard 1.0 so is available on all versions of .NET Core
Upvotes: 3
Reputation: 49779
As assembly could have multiple namespaces, you only could try to get namespaces of all types:
.GetTypeInfo().Assembly.GetTypes().Select(t => t.Namespace).Distinct();
Upvotes: 0