Search code examples
c#assemblies

Get all namespaces from .dll


In a DLL (GUI) I need to get a List of all namespaces in the current Application (so for example if I would bind that DLL into a Project named "Hundekuchen", it should List

{ "GUI", "Hundekuchen" }

Is there any inbuilt function for this?


Solution

  • Look into the System.Reflection namespace, this is where you will find the functionality to retrieve information about assemblies.

    This may not be exactly what you need but it shows the sort of things you can achieve, I am getting all the types in the currently executing assembly, iterates them and prints out the namespace of each type.

    foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
    {
        Console.WriteLine(t.Namespace);
    }
    

    Just inspect the Assembly class and you should find a way to solve your problem.