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 203753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:24:24+00:00 2026-05-11T17:24:24+00:00

I currently have an extension Method which converts an IEnumerable of type Tab into

  • 0

I currently have an extension Method which converts an IEnumerable of type Tab into a hierarchical collection of TabNodes.

// If Tab has no parent its ParentId is -1

public class Tab
{
public int TabId { get; set; }
    public string TabName { get; set; }
    public int Level { get; set; }
    public int ParentId { get; set; }

}

public class TabNode
{
    public TabInfo Tab { get; set; }
    public IEnumerable<TabNode> ChildNodes { get; set; }
    public int Depth { get; set; }
}

For instance, the following would give you a collection of TabNodes who are below a Parent with TabId 32 – the maximum level of depth is 4.

IEnumerable<Tab> tabs = GetTabs();

IEnumerable<TabNode> = tabs.AsNavigationHierarchy(32,4);

This is confusing and not very friendly for further refinement. What If I’d like to specify a certain Level instead of a ParentID?

What I’d like to do is something like this:

IEnumerable<TabNode> = tabs.AsNavigationHierarchy().WithStartLevel(2).WithMaxDepth(5)

I’m stuck as how to do this elegantly. Can you help me?

This is my current function which is called by my extension methods (based on an article I’ve found on http://www.scip.be).

    private static IEnumerable<TabNode>
      CreateHierarchy(
        IEnumerable<TabInfo> tabs,
        int startTabId,
        int maxDepth,
        int depth)
    {
        IEnumerable<TabInfo> children;


            children = tabs.Where(i => i.ParentId.Equals(startTabId));


        if (children.Count() > 0)
        {
            depth++;

            if ((depth <= maxDepth) || (maxDepth == 0))
            {
                foreach (var childTab in children)
                    yield return
                      new TabNode()
                      {
                          Tab = childTab,
                          ChildNodes =
                            CreateHierarchy(tabs, childTab.TabID, maxDepth, depth),
                          Depth = depth
                      };
            }
        }
    }
  • 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-11T17:24:24+00:00Added an answer on May 11, 2026 at 5:24 pm

    tabs.AsNavigationHeirachy could return a HerirchyQuery object which your next extension methods would then expect. This will let you chain them together.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 236k
  • Answers 236k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to do any more complex date manipulation,… May 13, 2026 at 6:25 am
  • Editorial Team
    Editorial Team added an answer <script type="text/javascript"> var ViewData_a = "<%= ViewData["a"] %>"; </script> ...… May 13, 2026 at 6:25 am
  • Editorial Team
    Editorial Team added an answer I don't think it's worth not duplicating the code here-… May 13, 2026 at 6:25 am

Related Questions

I have decided it is impossible to do the following (equivalent) enum operations via
I have an ASP.net Web Site Project (.net 3.5). Currently all of the non-code
I have a listview with 4 columns - Name, Extension, Size and Location. I
I'm working on a car dealer website at the moment, and I've been working

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.