/// <summary> /// If <paramref name="shellItem" /> is known folder, create a new instance of the <see cref="IKnownFolder" /> derived /// class. /// </summary> /// <param name="shellItem"><see cref="ShellItem" />.</param> /// <returns>Created a new instance of <see cref="IKnownFolder" /> derived class.</returns> private static IKnownFolder GetKnownFolderNative(ShellItem shellItem) { Contract.Requires(shellItem != null); var pidl = PIDL.FromShellItem(shellItem.ShellItemInterface); if (pidl.IsNull) { return(null); } return(ShellKnownFolderFactory.FromPIDL(pidl)); }
/// <summary> /// Initialize a new instance of the <see cref="ShellItem" /> class /// to the specified <see cref="IShellItem2" />. /// </summary> /// <param name="shellItem2"><see cref="IShellItem2" />.</param> internal ShellItem(IShellItem2 shellItem2) { Contract.Requires <ArgumentNullException>(shellItem2 != null); this.ShellItemInterface = shellItem2; this.PIDL = PIDL.FromShellItem(this.ShellItemInterface); try { var attributes = GetAttributes(SFGAO.SFGAO_LINK | SFGAO.SFGAO_FILESYSTEM | SFGAO.SFGAO_FOLDER); this.IsLink = (attributes & SFGAO.SFGAO_LINK) != 0; this.IsFileSystem = (attributes & SFGAO.SFGAO_FILESYSTEM) != 0; this.IsFolder = (attributes & SFGAO.SFGAO_FOLDER) != 0; } catch { this.IsLink = false; this.IsFileSystem = false; this.IsFolder = false; } }