I have transformed this XML tree with the names of the units: Dim = Dimension
Dim1
|---MG1
|---M1
|---M2
|---M3
|---MG31
|---MG32
Dim2
|---MG220
|---MG2222
…变成一个单位列表,也就是列表,每个单位都可以有另一个层次不受限制的列表。现在,我想将List转换为具有父/子层次结构的表格格式。
数据表应该是这样的:
Dimension...Parent..Child
Dim1........Dim1....MG1
Dim1........MG1.....M1
Dim1........MG1.....M2
Dim1........Dim1....MG2
Dim1........MG1.....M3
Dim1........M3......MG31
Dim1........M3......MG32
Dim2........Dim2....MG220
Dim2........MG220...MG2222
public class Unit
{
public String Name { get; set; }
public Unit Dimension { get; set; }
public UnitParent { get; set; }
public List<Unit> Children { get; set; }
}
Question: How would you iterate the List and write all the data into a DataTable ? There must be a tricky algoryth I can not find.