public static IFileSystemItem GetChild(this IFileSystemItemWithChildren self, IEnumerable <string> path) { var name = path.FirstOrDefault(); if (name == null) { return(self as IFileSystemItem); } var child = self.Children .FirstOrDefault(item => item.Name == name); var nextPaths = path.Skip(1).ToImmutableList(); if (nextPaths.IsEmpty) { return(child as IFileSystemItem); } var childWithChildren = child as IFileSystemItemWithChildren; if (childWithChildren != null) { child = childWithChildren.GetChild(nextPaths); } return(child); }
public static IFileSystemItem GetChild(this IFileSystemItemWithChildren self, string path) { var splitted = path.Split('\\'); var items = splitted .Where(item => !string.IsNullOrWhiteSpace(item)); var child = self.GetChild(items); return(child); }