public static List <ContentDir> CreateContentDirs(Dictionary <string, List <string> > paths) { List <ContentDir> toReturn = new List <ContentDir>(); foreach (var pair in paths) { ContentDir existingPath = AddOrCreate(pair.Value[0], toReturn); existingPath.FullPath = new List <string> { pair.Value[0] }; for (int i = 1; i < pair.Value.Count; i++) { List <string> path = existingPath.FullPath; existingPath = AddOrCreate(pair.Value[i], existingPath.Children); existingPath.FullPath.Clear(); existingPath.FullPath.AddRange(path); existingPath.FullPath.Add(pair.Value[i]); } List <string> finalPath = existingPath.FullPath; existingPath = AddOrCreate(pair.Key, existingPath.Children); existingPath.FullPath.AddRange(finalPath); existingPath.FullPath.Add(existingPath.Name); } return(toReturn); }
public static ContentDir AddOrCreate(string path, List <ContentDir> existingDirs) { ContentDir existingPath = existingDirs.FirstOrDefault(dir => dir.Name == path); if (existingPath == null) { ContentDir newDir = new ContentDir { Name = path }; existingDirs.Add(newDir); return(newDir); } else { return(existingPath); } }
public static ContentDir AddOrCreate(string path, List<ContentDir> existingDirs) { ContentDir existingPath = existingDirs.FirstOrDefault(dir => dir.Name == path); if(existingPath == null) { ContentDir newDir = new ContentDir { Name = path }; existingDirs.Add(newDir); return newDir; } else { return existingPath; } }