Exemple #1
0
        /// <summary>
        /// Gets the string key for a <see cref="Tool"/>.
        /// </summary>
        /// <param name="tool">The <see cref="Tool"/> to get the key for.</param>
        /// <returns>The key for the <paramref name="tool"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="tool"/> is null.</exception>
        protected static string GetToolKey(Tool tool)
        {
            if (tool == null)
            {
                throw new ArgumentNullException("tool");
            }

            return(tool.GetType().FullName);
        }
Exemple #2
0
        /// <summary>
        /// Handles the <see cref="Tool.Disposed"/> event of a <see cref="Tool"/> in this <see cref="ToolManager"/>.
        /// </summary>
        /// <param name="sender">The <see cref="Tool"/> the event came from.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        void tool_Disposed(Tool sender, EventArgs e)
        {
            if (sender == null)
            {
                Debug.Fail("How the hell was the sender null?");
                return;
            }

            try
            {
                // Remove the event hooks
                SetToolListeners(sender, false);

                // Remove the tool
                var wasRemoved = _tools.Remove(sender.GetType());

                if (wasRemoved)
                {
                    if (ToolRemoved != null)
                    {
                        ToolRemoved.Raise(this, EventArgsHelper.Create(sender));
                    }
                }

                Debug.Assert(wasRemoved);
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to remove tool `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, sender, ex);
                }
                Debug.Fail(string.Format(errmsg, sender, ex));
            }
        }
        /// <summary>
        /// Gets the string key for a <see cref="Tool"/>.
        /// </summary>
        /// <param name="tool">The <see cref="Tool"/> to get the key for.</param>
        /// <returns>The key for the <paramref name="tool"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="tool"/> is null.</exception>
        protected static string GetToolKey(Tool tool)
        {
            if (tool == null)
                throw new ArgumentNullException("tool");

            return tool.GetType().FullName;
        }