我有一个像下面的模型
public class Path
{
public string Name {get; set;}
public IEnumerable<Path> Items {get; set;}
}
& List<Path>
中单个项目的列表数据表示形式,如下所示
new List<path>
{
new Path
{
Name = "FirstRoot",
Items = new List<Path>
{
new Path
{
Name = "2023",
Items = new List<Path>
{
new Path
{
Name = "01",
Items = new List<Path>
{
new Path
{
Name = "01"
Items = new List<Path>
{
new Path
{
Name = "01.text"
Items = null,
}
}
}
}
}
}
}
}
},
new Path
{
Name = "FirstRoot",
Items = new List<Path>
{
new Path
{
Name = "2023",
Items = new List<Path>
{
new Path
{
Name = "01",
Items = new List<Path>
{
new Path
{
Name = "01"
Items = new List<Path>
{
new Path
{
Name = "02.text"
Items = null,
}
}
}
}
}
}
}
}
},
...
}
- FirstRoot - 2023 - 01 - 01.text
- FirstRoot - 2023 - 01 - 02.text
- SecondRoot - 2023 - 01 - 01.text
- SecondRoot - 2023 - 01 - 02.text
- ThirdRoot - 2023 - 01.text
- ThirdRoot - 2023 - 02.text
现在我如何从中得到唯一路径,使我的列表看起来像
new List<path>
{
new Path
{
Name = "FirstRoot",
Items = new List<Path>
{
new Path
{
Name = "2023",
Items = new List<Path>
{
new Path
{
Name = "01",
Items = new List<Path>
{
new Path
{
Name = "01"
Items = new List<Path>
{
new Path
{
Name = "01.text"
Items = null,
},
new Path
{
Name = "02.text"
Items = null,
},
}
}
}
}
}
}
}
},
new Path
{
Name = "SecondRoot",
Items = new List<Path>
{
new Path
{
Name = "2023",
Items = new List<Path>
{
new Path
{
Name = "01",
Items = new List<Path>
{
new Path
{
Name = "01"
Items = new List<Path>
{
new Path
{
Name = "01.text"
Items = null,
},
new Path
{
Name = "02.text"
Items = null,
},
}
}
}
}
}
}
}
},
...
}
我试着看看this解决方案,但找不到一个。
1条答案
按热度按时间bxjv4tth1#
我设法得到了一个工作代码,张贴在这里,如果它帮助任何人。