Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3852276
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:17:36+00:00 2026-05-19T17:17:36+00:00

To put it simple, I want all the namespaces in the project recursively, and

  • 0

To put it simple, I want all the namespaces in the project recursively, and classes available in all namespaces found earlier.

var namespaces = assembly.GetTypes()
                  .Select(ns => ns.Namespace);

I am using this part earlier to get the namespaces in string format.
But now i got to know the underlying namespaces as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:17:37+00:00Added an answer on May 19, 2026 at 5:17 pm

    It sounds like you might want a Lookup from namespace to class:

    var lookup = assembly.GetTypes().ToLookup(t => t.Namespace);
    

    Or alternatively (and very similarly) you could use GroupBy:

    var groups = assembly.GetTypes().GroupBy(t => t.Namespace);
    

    For example:

    var groups = assembly.GetTypes()
                         .Where(t => t.IsClass) // Only include classes
                         .GroupBy(t => t.Namespace);
    foreach (var group in groups)
    {
        Console.WriteLine("Namespace: {0}", group.Key);
        foreach (var type in group)
        {
            Console.WriteLine("  {0}", t.Name);
        }
    }
    

    However, it’s not entirely clear whether that’s what you’re after. That will get you the classes in each namespace, but I don’t know whether that’s really what you’re looking for.

    Two points to bear in mind:

    • There’s nothing recursive about this
    • Namespaces don’t really form a hierarchy, as far as the CLR is concerned. There’s no such thing as an “underlying” namespace. The C# language itself does have some rules about this, but as far as the CLR is concerned, there’s no such thing as a “parent” namespace.

    If you really want to go from “Foo.Bar.Baz” to “Foo.Bar” and “Foo” then you can use something like:

    while (true)
    {
        Console.WriteLine(ns);
        int index = ns.LastIndexOf('.');
        if (index == -1)
        {
            break;
        }
        ns = ns.Substring(0, index);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Put simply, I want to select all data in two columns from each of
Shamed by this simple question. For some reason, I want to put all asp.net
I want to put together simple TCP server using Python and Twisted. The server
I want to write a simple applet to put in a tray. Let's say
A simple question, I think: I want to put a tag into an ASP.NET
I have something pretty simple I want to do. I'm still working through all
I have an interesting stack of assemblies I want to put together: Common Assembly
All i want to do in simple words: When input value is changed, i'll
I thought this would be simple: all I want is for JS to detect
I need a really simple ItemsControl actually. I want all the items in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.