private List<TreeItem<FileLayerSongDO>> BuildTree(IEnumerable<Tuple<int, List<string>>> data, int depth) { // wenn depth == items2.length // break; var grped = from r in (from item in data where item.Item2.Count > depth select item) group r by r.Item2[depth] into grp select grp; List<TreeItem<FileLayerSongDO>> result = null; if (grped.Any()) { result = new List<TreeItem<FileLayerSongDO>>(); foreach (var item in grped) { var child = new TreeItem<FileLayerSongDO>(); child.Level = depth; var temp = new FileLayerSongDO(); temp.SetByDepth(depth, item.Key); var current = item.First(); if (depth == current.Item2.Count - 1) temp.ID = item.First().Item1; child.Value = temp; var childs = BuildTree(item, depth + 1); if (childs != null) child.SetChildren(childs); result.Add(child); } } return result; }