给定以下对象:
public class Round
{
public Round Parent { get; set; }
public int Depth { get; set; }
public string Value { get; set; }
}
和下面的代码......
var rounds = new List<Round>();
var a1 = new Round { Depth = 0, Value = "a1" };
var b1 = new Round { Depth = 1, Value = "b1", Parent = a1 };
var c1 = new Round { Depth = 2, Value = "c1", Parent = b1 };
var b2 = new Round { Depth = 1, Value = "b1", Parent = a1 };
var a2 = new Round { Depth = 0, Value = "a2", };
var b2 = new Round { Depth = 1, Value = "b2", Parent = a2 };
现在我想将其映射List
到某种 Node 结构,如下所示:
Node {
Value = "a1",
Depth = 0,
Nodes = Nodes[] {
Node {
Value = "b1",
Depth = 1,
Nodes = Nodes[] {
Node { Value = "c1", Depth = 2 } } },
Node {
Value = "b2",
Depth = 1 } } }
Node {
Value = "a2",
Depth = 0,
Nodes = Nodes[] {
Node {
Value = "b2",
Depth = 1 } } }
但是我完全不知道如何映射它。
任何提示表示赞赏。