private IEnumerable <Pidl> EnumerateChildPidls(Native.SHCONTF flags) { if (!_isFolder) { throw new InvalidOperationException("Children can only be enumerated on a folder-type item."); } if (_shellFolder == null) { return(new Pidl[0]); } // Get the IEnumIDList interface pointer. Native.IEnumIDList pEnum = null; uint hRes = _shellFolder.EnumObjects(IntPtr.Zero, flags, out pEnum); if (hRes != 0) { throw new Exception("IShellFolder::EnumObjects failed to enumerate child objects.", Marshal.GetExceptionForHR((int)hRes)); } try { return(Pidl.ConvertPidlEnumeration(pEnum)); } finally { // Free the interface pointer. Marshal.ReleaseComObject(pEnum); } }
public IEnumerable <Pidl> EnumerateChildPidls(ChildType types, bool includeHiddenItems) { Native.SHCONTF flags = 0; flags |= ((types & ChildType.Files) == ChildType.Files) ? Native.SHCONTF.SHCONTF_NONFOLDERS : 0; flags |= ((types & ChildType.Folders) == ChildType.Folders) ? Native.SHCONTF.SHCONTF_FOLDERS : 0; flags |= (includeHiddenItems) ? Native.SHCONTF.SHCONTF_INCLUDEHIDDEN : 0; return(this.EnumerateChildPidls(flags)); }
public IEnumerable <ShellItem> EnumerateChildren(ChildType types, bool includeHiddenItems) { Native.SHCONTF flags = 0; flags |= ((types & ChildType.Files) == ChildType.Files) ? Native.SHCONTF.SHCONTF_NONFOLDERS : 0; flags |= ((types & ChildType.Folders) == ChildType.Folders) ? Native.SHCONTF.SHCONTF_FOLDERS : 0; flags |= (includeHiddenItems) ? Native.SHCONTF.SHCONTF_INCLUDEHIDDEN : 0; List <ShellItem> children = new List <ShellItem>(); foreach (Pidl pidl in EnumerateChildPidls(flags)) { children.Add(new ShellItem(pidl, this)); pidl.Dispose(); } return(children); }