public void Apply(Menu m) { m.Name = Name; m.Items = new List<MenuItem>(); var j = new Stack<MenuItem>(); foreach (var i in Items) { var a = new MenuItem {Name = i.Name, Type = i.Type, Location = i.Location}; if (i.Indent == 0) { j.Clear(); j.Push(a); m.AddItem(a); } else { // rewind the that stack until we reach the parent node. creates the // effect the stack always represents a 'stair-step' pattern while (j.Count > i.Indent) j.Pop(); j.Peek().AddItem(a); j.Push(a); } } }
public void AddItem(MenuItem i) { (Items ?? (Items = new List<MenuItem>())).Add(i); }