public BaseComposite(string fullpath, BaseComposite parent, List <BaseComposite> children = null) { if (string.IsNullOrWhiteSpace(fullpath)) { throw new NullReferenceException("Cannot initialize a BaseComposite instance with a null/empty path"); } Name = fullpath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries).Last(); FullPath = fullpath; Parent = parent; _children = children ?? (IsDirectory ? new List <BaseComposite>() : null); }
protected static HashSet <BaseComposite> Search(Regex pattern, BaseComposite item, HashSet <BaseComposite> results, bool recursive) { //Initialize if needed results = results ?? new HashSet <BaseComposite>(); if (!item.IsDirectory && pattern.IsMatch(item.Name)) { results.Add(item); } else { item.Children.Where(c => pattern.IsMatch(c.Name)).Select(r => results.Add(r)); if (recursive) { item.Children.SelectMany(c => Search(pattern, c, null, recursive)).Select(r => results.Add(r)); } } return(results); }
public FileItem(string fullpath, BaseComposite parent) : base(fullpath, parent) { }
public FolderItem(string fullPath, BaseComposite parent) : base(fullPath, parent) { }