/// <summary> /// /// </summary> public void Reset() { if (nativeEnumIdList != null) { nativeEnumIdList.Reset(); } }
public void Reset() { if (nativeEnumIdList is object) { Marshal.ThrowExceptionForHR((int)nativeEnumIdList.Reset()); } }
/// <summary> /// Enumerates all children of this item. If this item is not a folder/container, this method will return an empty enumeration. /// </summary> /// <param name="filter">A filter for the types of children to enumerate.</param> /// <param name="parentWindow">The parent window.</param> /// <returns>An enumerated list of children matching the filter.</returns> public IEnumerable <ShellItem> EnumerateChildren(FolderItemFilter filter /*= FolderItemFilter.Folders | FolderItemFilter.IncludeHidden | FolderItemFilter.NonFolders | FolderItemFilter.IncludeSuperHidden */, System.Windows.Forms.IWin32Window parentWindow = null) { IEnumIDList eo = null; try { eo = iShellFolder.EnumObjects(IWin2Ptr(parentWindow, false), (SHCONTF)filter); } catch (Exception e) { Debug.WriteLine($"Unable to enum children in folder: {e.Message}"); } if (eo != null) { foreach (var p in new Collections.IEnumFromNext <IntPtr>((out IntPtr p) => eo.Next(1, out p, out var f).Succeeded&& f == 1, () => { try { eo.Reset(); } catch { } })) { ShellItem i = null; try { i = this[new PIDL(p)]; } catch (Exception e) { Debug.WriteLine($"Unable to open folder child: {e.Message}"); } if (i != null) { yield return(i); } } Marshal.ReleaseComObject(eo); } }