Click here to Skip to main content
15,891,976 members
Articles / Programming Languages / C#

A Flexible Plugin System

Rate me:
Please Sign up or sign in to vote.
4.98/5 (25 votes)
3 Sep 2008LGPL34 min read 131.4K   1.8K   163  
A generic plugin system used to load and manage plugins
using System;

namespace Fadd.Commands
{
    /// <summary>
    /// Delegate used to handle commands.
    /// </summary>
    /// <param name="source"><see cref="ICommandDispatcher"/> that the command was invoked in.</param>
    /// <returns>true if command was handled.</returns>
    /// <param name="args">command arguments.</param>
    public delegate bool CommandHandler(object source, CommandEventArgs args);

    /// <summary>
    /// Event arguments for <see cref="CommandHandler"/>.
    /// </summary>
    public class CommandEventArgs : EventArgs
    {
        private readonly Command _command;
        private bool _cancelPropagation;
        private readonly bool _asynchronous;

        /// <summary>
        /// Initializes a new instance of the <see cref="CommandEventArgs"/> class.
        /// </summary>
        /// <param name="command">command that was invoked.</param>
        public CommandEventArgs(Command command)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            _command = command;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CommandEventArgs"/> class.
        /// </summary>
        /// <param name="command">command that was invoked.</param>
        /// <param name="isAsynchrounous">Command is being invoked asynchrounosly.</param>
        public CommandEventArgs(Command command, bool isAsynchrounous)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            _command = command;
            _asynchronous = isAsynchrounous;
        }

        /// <summary>
        /// Command that was invoked.
        /// </summary>
        public Command Command
        {
            get { return _command; }
        }

        /// <summary>
        /// Abort the handled of this command.
        /// </summary>
        /// <remarks>
        /// The event <see cref="CommandManager.PropagationCancelled"/> can override this property.
        /// </remarks>
        public bool CancelPropagation
        {
            get { return _cancelPropagation; }
            set { _cancelPropagation = value; }
        }

        /// <summary>
        /// Command is being invoked asynchrounosly.
        /// </summary>
        public bool IsAsynchronous
        {
            get { return _asynchronous; }
        }
    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Founder 1TCompany AB
Sweden Sweden

Comments and Discussions