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

  • Home
  • SEARCH
  • 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

Related Questions

I am currently working on a Magento extension, and I have overridden a core
I currently have a table of concentrations, which are linked to a table of
I currently have 4 tables. Product, Category, SubCategory, ProductSubCategory. Category has a OneToMany SubCategory
I want to have an extension method for XElement/XAttribute that allows me to apply
I'm currently trying to install a few modules via virtualenv , which I have
I currently have quite the predicament. An if statement I have written - which
I need a Dictionary<string,object> which is produced from a DataRow. I currently have something
I'm currently using this extension to set specific events which handle data in the
I am creating an Extension method for the .net BindingSource object. Currently the method
Currently have a drop down menu that is activated on a hover (from display:none

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.