Skip to content

Instantly share code, notes, and snippets.

@PeterStegnar
Last active December 14, 2015 18:09
Show Gist options
  • Save PeterStegnar/5127896 to your computer and use it in GitHub Desktop.
Save PeterStegnar/5127896 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SO.15318438
{
class Program
{
static void Main(string[] args)
{
BoxNode boxNode = new BoxNode(){BoxChildren = new List<Box>()};
boxNode.BoxChildren.Add(new Box(){BoxNode = null, Name = "1Level1_0C" });
boxNode.BoxChildren.Add(new Box() { BoxNode =
new BoxNode() { BoxChildren = new List<Box>() { new Box() { BoxNode = null, Name = "2Level1_0C" }, new Box() { BoxNode = null, Name = "2Level2_0C" } } },
Name = "1Level2_2C" });
CreateMenuTree(boxNode, " ");
Console.ReadLine();
}
public static void CreateMenuTree(BoxNode boxNode, string indent)
{
foreach (Box box in boxNode.BoxChildren)
{
Console.WriteLine(indent + box.Name);
if (box.BoxNode != null && box.BoxNode.BoxChildren != null && box.BoxNode.BoxChildren.Count > 0)
{
CreateMenuTree(box.BoxNode, indent + indent);
}
}
}
}
public class BoxNode
{
public List<Box> BoxChildren
{
get;
set;
}
}
public class Box
{
public string Name
{
get;
set;
}
public BoxNode BoxNode
{
get;
set;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment