//~ Methods ..........................................................

        // ------------------------------------------------------
        /// <summary>
        /// Returns true if two hierarchy items are the same (that is, they
        /// contain the same hierarchy interface and item ID).
        /// </summary>
        /// <param name="obj">
        /// The object to compare to this hierarchy item.
        /// </param>
        /// <returns>
        /// True if the hierarchy items are the same; false if they are not, or
        /// if the given object is not a hierarchy item.
        /// </returns>
        public override bool Equals(object obj)
        {
            HierarchyItem rhs = obj as HierarchyItem;

            if (rhs != null)
            {
                return(CanonicalName == rhs.CanonicalName);
            }
            else
            {
                return(false);
            }
        }
        // ------------------------------------------------------
        /// <summary>
        /// Gets an array of hierarchy items that represent the currently
        /// selected items in the Solution Explorer.
        /// </summary>
        /// <param name="provider">
        /// The DTE object to use as a service provider.
        /// </param>
        /// <returns>
        /// An array of HierarchyItem objects that are currently selected.
        /// </returns>
        public static HierarchyItem[] GetCurrentSelection(
            IServiceProvider provider)
        {
            IVsMonitorSelection vsms = (IVsMonitorSelection)
                                       provider.GetService(typeof(SVsShellMonitorSelection));

            IntPtr             hierPtr;
            uint               itemID;
            IVsMultiItemSelect multiSel;
            IntPtr             selCont;

            vsms.GetCurrentSelection(out hierPtr, out itemID, out multiSel,
                                     out selCont);

            if (itemID == VSConstants.VSITEMID_SELECTION)
            {
                // Multiple selection

                uint count;
                int  isSingle;
                multiSel.GetSelectionInfo(out count, out isSingle);

                VSITEMSELECTION[] selection = new VSITEMSELECTION[count];
                multiSel.GetSelectedItems(0, count, selection);

                HierarchyItem[] hierItems = new HierarchyItem[count];
                int             i         = 0;
                foreach (VSITEMSELECTION selectedItem in selection)
                {
                    hierItems[i++] = new HierarchyItem(selectedItem.pHier,
                                                       selectedItem.itemid);
                }

                return(hierItems);
            }
            else if (hierPtr != IntPtr.Zero)
            {
                // Single selection

                IVsHierarchy hier = IntPtrToInterface <IVsHierarchy>(hierPtr);

                return(new HierarchyItem[] {
                    new HierarchyItem(hier, itemID)
                });
            }
            else
            {
                return(new HierarchyItem[] { });
            }
        }