我需要使用路径列表中的对象构建树形列表。下面的代码可以工作,但是我无法从搜索函数中检索完整路径。请注意加粗的代码...
public List<RestoreTreeViewModel> BuildTree(IEnumerable<string> strings)
{
return (
from path in strings
let split = path.Split('\\')
group path by path.Split('\\')[0] into g
select new RestoreTreeViewModel()
{
Name = g.Key,
Nodetype = 2,
CanReference = true,
**FullPath = path;**
Children = BuildTree(
from s in g
where s.Length > g.Key.Length + 1
select s.Substring(g.Key.Length + 1))
}
).ToList();
}
这个能行吗,还是我应该探索另一种从路径列表构建树的方法?
from s in g where s.Length > g.Key.Length + 1 select s.Substring(g.Key.Length + 1)) } ).ToList(); } - user1789782