문제

I need to build a tree list with objects from a path list. The code below works, but I'm unable to retrieve the full path from the search function. See code in bold...

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();
}

Can this work or should I investigate another way to build the tree from the path list?

도움이 되었습니까?

해결책

You need to add a list parameter to your BuildTree() method, and then append (or prepend) items to that list so the end result will contain all the items in the path.

There are other ways to approach it, but that seems straight forward if I understood what you are trying to do.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top