Exemplo n.º 1
0
        /// <summary>Initializes a new instance of the <see cref="ShellItem"/> class.</summary>
        /// <param name="parent">The parent Shell item.</param>
        /// <param name="pidl">The ID List of the child.</param>
        public ShellItem(ShellItem parent, PIDL pidl)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            if (pidl == null || pidl.IsInvalid)
            {
                throw new ArgumentNullException(nameof(pidl));
            }
            if (!parent.IsFolder)
            {
                throw new ArgumentException("Parent argument must be a folder.");
            }

            object ppv;

            if (IsMinVista)
            {
                SHCreateItemWithParent(PIDL.Null, parent.GetIShellFolder(), pidl, typeof(IShellItem).GUID, out ppv);
            }
            else
            {
                var idList = PIDL.Combine(parent.PIDL, pidl);
                ppv = new ShellItemImpl(idList, false);
            }
            Init((IShellItem)ppv);
        }
Exemplo n.º 2
0
        /// <summary>Gets a child <see cref="ShellItem"/> reference from a parent and child PIDL.</summary>
        /// <param name="relativePidl">A valid relative PIDL.</param>
        /// <returns>A child <see cref="ShellItem"/> reference.</returns>
        public ShellItem this[PIDL relativePidl]
        {
            get
            {
                if (relativePidl == null || relativePidl.IsInvalid)
                {
                    throw new ArgumentNullException(nameof(relativePidl));
                }

                object ppv;
                if (IsMinVista)
                {
                    SHCreateItemWithParent(PIDL.Null, iShellFolder, relativePidl, typeof(IShellItem).GUID, out ppv);
                }
                else
                {
                    ppv = new ShellItemImpl(PIDL.Combine(PIDL, relativePidl), false);
                }
                return(Open((IShellItem)ppv));
            }
        }
Exemplo n.º 3
0
        /// <summary>Gets the <see cref="ShellItem"/> with the specified child name.</summary>
        /// <value>The <see cref="ShellItem"/> instance matching <paramref name="childName"/>.</value>
        /// <param name="childName">Name of the child item.</param>
        /// <returns>The <see cref="ShellItem"/> instance matching <paramref name="childName"/>, if it exists.</returns>
        public ShellItem this[string childName]
        {
            get
            {
                if (string.IsNullOrEmpty(childName))
                {
                    throw new ArgumentNullException(nameof(childName));
                }

                object ppv;
                if (IsMinVista)
                {
                    SHCreateItemFromRelativeName(iShellItem, childName, BindContext, typeof(IShellItem).GUID, out ppv).ThrowIfFailed();
                }
                else
                {
                    SFGAO attr = 0;
                    iShellFolder.ParseDisplayName(IntPtr.Zero, null, childName, out uint _, out var tempPidl, ref attr);
                    ppv = new ShellItemImpl(PIDL.Combine(PIDL, tempPidl), false);
                }
                return(Open((IShellItem)ppv));
            }
        }