我需要用路径列表中的对象构建一个树列表。下面的代码有效,但我无法从搜索功能中检索完整路径。请参阅粗体代码...
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();
}
这可以工作还是我应该研究另一种从路径列表构建树的方法?