/// <summary> /// Initialize a new instance of the <see cref="ShellFolder" /> class /// to the specified <see cref="ShellItem" />. /// </summary> /// <param name="shellItem"><see cref="ShellItem" />.</param> /// <remarks> /// <para> /// <See cref="ShellItem.IsFolder" /> is not necessarily <c>true</c>. /// For some <c>KnownFolder</c>, <see cref="ShellItem.IsFolder" /> may be <c>false</c>. /// </para> /// </remarks> internal ShellFolder(ShellItem shellItem) : base(shellItem) { Contract.Requires <ArgumentNullException>(shellItem != null); this.ShellFolderItem = ShellFolderItem.FromShellItem(shellItem); }
/// <summary> /// Create new instance of the <see cref="ShellItem" /> class /// to the specified <c>IDListPtr</c> and parent <see cref="IShellFolder" />. /// </summary> /// <param name="idListPtr"><c>IDListPtr</c>.</param> /// <param name="parentFolder">Parent <see cref="ShellFolderItem" />.</param> /// <returns><see cref="ShellItem" />.</returns> /// <exception cref="ArgumentNullException"><paramref name="idListPtr" /> is <see cref="IntPtr.Zero" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="parentFolder" /> is <c>null</c>.</exception> /// <exception cref="ShellException">Failed to create <see cref="ShellItem" />.</exception> internal static ShellItem FromIdList(IntPtr idListPtr, ShellFolderItem parentFolder) { Contract.Requires <ArgumentNullException>(idListPtr != IntPtr.Zero); Contract.Requires <ArgumentNullException>(parentFolder != null); Contract.Ensures(Contract.Result <ShellItem>() != null); IShellItem shellItem; var code = ShellNativeMethods.SHCreateItemWithParent( IntPtr.Zero, parentFolder.ShellFolderInterface, idListPtr, ShellIIDGuid.IShellItem2, out shellItem); if (HRESULT.Failed(code)) { throw new ShellException(ErrorMessages.ShellFactoryUnableToCreateItem, Marshal.GetExceptionForHR(code)); } return(new ShellItem((IShellItem2)shellItem)); }