Ejemplo n.º 1
0
        /// <summary>
        /// Is the current <paramref name="checkedItem">Item</paramref> in the <paramref name="currentFolder">Folder</paramref>?
        /// </summary>
        /// <param name="checkedItem">The current item who's container/parent you want to check</param>
        /// <param name="currentFolder">The folder you are looking for</param>
        /// <returns>Is the current <paramref name="checkedItem">Item</paramref> in the <paramref name="currentFolder">Folder</paramref>?</returns>
        /// <remarks>
        /// 1. Special Logic for Library folders (.library-ms)
        /// </remarks>
        public static Boolean IsInCurrentFolder(this IListItemEx checkedItem, IListItemEx currentFolder)
        {
            var isLibraryContainer = currentFolder?.Extension == ".library-ms";

            if (isLibraryContainer)
            {
                var library        = ShellLibrary.Load(currentFolder.DisplayName, true);
                var libraryFolders = library.Select(w => w).ToArray();
                if (libraryFolders.Count(
                        c => c.ParsingName.Equals(checkedItem.Parent?.ParsingName, StringComparison.InvariantCultureIgnoreCase)) > 0)
                {
                    library.Close();
                    return(true);
                }
                library.Close();
                return(false);
            }
            else
            {
                return(checkedItem?.Parent?.ParsingName == currentFolder?.ParsingName);
            }
        }