// ------------------------------------------------------
        /// <summary>
        /// Unhooks the specified delegates from the code model event sink.
        /// </summary>
        /// <param name="elementAdded">
        /// A delegate that was previously registered to be called when an
        /// element is added to the code model.
        /// </param>
        /// <param name="elementChanged">
        /// A delegate that was previously registered to be called when an
        /// element changes in the code model.
        /// </param>
        /// <param name="elementDeleted">
        /// A delegate that was previously registered to be called when an
        /// element is deleted from the code model.
        /// </param>
        public void UnadviseCodeModelEvents(
            _dispCodeModelEvents_ElementAddedEventHandler elementAdded,
            _dispCodeModelEvents_ElementChangedEventHandler elementChanged,
            _dispCodeModelEvents_ElementDeletedEventHandler elementDeleted)
        {
            // This might be called as a consequence of closing the IDE, in
            // which case this would fail, so wrap it in a try/catch.

            try
            {
                DTE             dte      = (DTE)GetService(typeof(DTE));
                Events2         events   = (Events2)((DTE2)dte).Events;
                CodeModelEvents cmEvents = events.get_CodeModelEvents(null);

                if (cmEvents != null)
                {
                    if (elementAdded != null)
                    {
                        cmEvents.ElementAdded -= elementAdded;
                    }

                    if (elementChanged != null)
                    {
                        cmEvents.ElementChanged -= elementChanged;
                    }

                    if (elementDeleted != null)
                    {
                        cmEvents.ElementDeleted -= elementDeleted;
                    }
                }
            }
            catch (Exception) { }
        }
        // ------------------------------------------------------
        /// <summary>
        /// Hooks the specified delegates into the code model event sink.
        /// </summary>
        /// <param name="elementAdded">
        /// A delegate to be called when an element is added to the code
        /// model.
        /// </param>
        /// <param name="elementChanged">
        /// A delegate to be called when an element changes in the code model.
        /// </param>
        /// <param name="elementDeleted">
        /// A delegate to be called when an element is deleted from the code
        /// model.
        /// </param>
        public void AdviseCodeModelEvents(
            _dispCodeModelEvents_ElementAddedEventHandler elementAdded,
            _dispCodeModelEvents_ElementChangedEventHandler elementChanged,
            _dispCodeModelEvents_ElementDeletedEventHandler elementDeleted)
        {
            DTE             dte      = (DTE)GetService(typeof(DTE));
            Events2         events   = (Events2)((DTE2)dte).Events;
            CodeModelEvents cmEvents = events.get_CodeModelEvents(null);

            if (cmEvents != null)
            {
                if (elementAdded != null)
                {
                    cmEvents.ElementAdded += elementAdded;
                }

                if (elementChanged != null)
                {
                    cmEvents.ElementChanged += elementChanged;
                }

                if (elementDeleted != null)
                {
                    cmEvents.ElementDeleted += elementDeleted;
                }
            }
        }
        // ------------------------------------------------------
        /// <summary>
        /// Unhooks the specified delegates from the code model event sink.
        /// </summary>
        /// <param name="elementAdded">
        /// A delegate that was previously registered to be called when an
        /// element is added to the code model.
        /// </param>
        /// <param name="elementChanged">
        /// A delegate that was previously registered to be called when an
        /// element changes in the code model.
        /// </param>
        /// <param name="elementDeleted">
        /// A delegate that was previously registered to be called when an
        /// element is deleted from the code model.
        /// </param>
        public void UnadviseCodeModelEvents(
			_dispCodeModelEvents_ElementAddedEventHandler elementAdded,
			_dispCodeModelEvents_ElementChangedEventHandler elementChanged,
			_dispCodeModelEvents_ElementDeletedEventHandler elementDeleted)
        {
            // This might be called as a consequence of closing the IDE, in
            // which case this would fail, so wrap it in a try/catch.

            try
            {
                DTE dte = (DTE)GetService(typeof(DTE));
                Events2 events = (Events2)((DTE2)dte).Events;
                CodeModelEvents cmEvents = events.get_CodeModelEvents(null);

                if (cmEvents != null)
                {
                    if (elementAdded != null)
                        cmEvents.ElementAdded -= elementAdded;

                    if (elementChanged != null)
                        cmEvents.ElementChanged -= elementChanged;

                    if (elementDeleted != null)
                        cmEvents.ElementDeleted -= elementDeleted;
                }
            }
            catch (Exception) { }
        }
        // ------------------------------------------------------
        /// <summary>
        /// Hooks the specified delegates into the code model event sink.
        /// </summary>
        /// <param name="elementAdded">
        /// A delegate to be called when an element is added to the code
        /// model.
        /// </param>
        /// <param name="elementChanged">
        /// A delegate to be called when an element changes in the code model.
        /// </param>
        /// <param name="elementDeleted">
        /// A delegate to be called when an element is deleted from the code
        /// model.
        /// </param>
        public void AdviseCodeModelEvents(
			_dispCodeModelEvents_ElementAddedEventHandler elementAdded,
			_dispCodeModelEvents_ElementChangedEventHandler elementChanged,
			_dispCodeModelEvents_ElementDeletedEventHandler elementDeleted)
        {
            DTE dte = (DTE)GetService(typeof(DTE));
            Events2 events = (Events2)((DTE2)dte).Events;
            CodeModelEvents cmEvents = events.get_CodeModelEvents(null);

            if (cmEvents != null)
            {
                if (elementAdded != null)
                    cmEvents.ElementAdded += elementAdded;

                if (elementChanged != null)
                    cmEvents.ElementChanged += elementChanged;

                if (elementDeleted != null)
                    cmEvents.ElementDeleted += elementDeleted;
            }
        }