CSharp · Console
using System.Collections.Generic;
using System.Linq;
public class MacroTab
{
public MacroTab()
{
Tabs = new List<Tab>();
}
public int IDMacroTab { get; set; }
public List<Tab> Tabs { get; set; }
}
public class Tab
{
public Tab()
{
Slots = new List<Slot>();
}
public int IDTab { get; set; }
public List<Slot> Slots { get; set; }
}
public class Slot
{
public int IDSlot { get; set; }
}
public class Program
{
public static void Main()
{
List<MacroTab> hierarchaldata = CreateHierarchaldata();
//Flatten
var flattenedList = (from macroTab in hierarchaldata
from tab in macroTab.Tabs
from slot in tab.Slots
select new {macroTab.IDMacroTab, tab.IDTab, slot.IDSlot}).ToList();
//Save the c# instructions to
//string linesOfCode = ExportDataToCSharpForUnitTesting(flattenedList);
// should return
// flattenedList = new List {
// { IDMacroTab = 1, IDTab = 1, IDSIot = 2 }
// { IDMacroTab = 1, IDTab = 2, IDSIot 1}
// { IDMacroTab = 1, IDTab = 2, IDSIot = 2}
// { IDMacroTab = 1, IDTab = 2, IDSIot = 3}
// { IDMacroTab = 2, IDTab = 1, IDSIot = 1}
// { IDMacroTab = 2, IDTab = 1, IDSIot = 2 }
// { IDMacroTab = 2, IDTab = 2, IDSIot = 1}
// { IDMacroTab = 2, IDTab = 2, IDSIot = 2}
// { IDMacroTab = 2, IDTab = 2, IDSIot = 3}
// { IDMacroTab = 3, IDTab = 1, IDSIot = 1}
// { IDMacroTab = 3, IDTab = 1, IDSIot = 2}
// { IDMacroTab = 3, IDTab = 2, IDSIot = 1}
// { IDMacroTab = 3, IDTab = 2, IDSIot = 2}
// { IDMacroTab = 3, IDTab = 2, IDSIot = 3}};
;
List<MacroTab> CreateHierarchaldata()
{
List<MacroTab> p = new List<MacroTab>()
{
new MacroTab
{
IDMacroTab = 1,
Tabs = new List<Tab>
{
new Tab
{
IDTab = 1,
Slots = new List<Slot>()
{
new Slot {IDSlot = 1},
new Slot {IDSlot = 2}
}
},
new Tab
{
IDTab = 2,
Slots = new List<Slot>()
{
new Slot {IDSlot = 1},
new Slot {IDSlot = 2},
new Slot {IDSlot = 3},
}
},
new Tab {IDTab = 3}
}
},
new MacroTab
{
IDMacroTab = 2,
Tabs = new List<Tab>
{
new Tab
{
IDTab = 1,
Slots = new List<Slot>()
{
new Slot {IDSlot = 1},
new Slot {IDSlot = 2}
}
},
new Tab
{
IDTab = 2,
Slots = new List<Slot>()
{
new Slot {IDSlot = 1},
new Slot {IDSlot = 2},
new Slot {IDSlot = 3},
}
},
new Tab {IDTab = 3}
}
},
new MacroTab
{
IDMacroTab = 3,
Tabs = new List<Tab>
{
new Tab
{
IDTab = 1,
Slots = new List<Slot>()
{
new Slot {IDSlot = 1},
new Slot {IDSlot = 2}
}
},
new Tab
{
IDTab = 2,
Slots = new List<Slot>()
{
new Slot {IDSlot = 1},
new Slot {IDSlot = 2},
new Slot {IDSlot = 3},
}
},
new Tab {IDTab = 3}
}
},
};
return p;
}
}
}