Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top