Click here to Skip to main content
12,303,543 members (76,491 online)
Click here to Skip to main content

Stats

81.5K views
1.5K downloads
159 bookmarked
Posted

A Flexible Plugin System

, 3 Sep 2008 LGPL3
A generic plugin system used to load and manage plugins
trunk
dlls
xunit.dll
Examples
Plugins
ExampleApplication.Shared
Properties
ExampleApplication
Properties
ExamplePlugin.Shared
Properties
ExamplePlugin
Properties
Fadd.Globalization.Yaml
fadd.snk
Properties
Tests
fadd
Commands
Net
Tests
fadd.snk
Globalization
Tests
Logging
Plugins
Properties
Tests
Validation
using System;
using System.Collections.Generic;

namespace Fadd.Plugins
{
    /// <summary>
    /// A found plugin and which of the requested types that it implements.
    /// </summary>
    [Serializable]
    public class PluginTypeInfo
    {
        private readonly string _assembly;
        private readonly List<Type> _types = new List<Type>();
        private readonly string _publicKey;
        private readonly byte[] _publicKeyRaw;

        /// <summary>
        /// Initializes a new instance of the <see cref="PluginTypeInfo"/> class.
        /// </summary>
        /// <param name="assemblyLocation">assembly that the plugin resides in.</param>
        /// <param name="type">plugin type.</param>
        /// <param name="publicKey">assemblies public key. should be used to decide the amount of access for the module.</param>
        public PluginTypeInfo(string assemblyLocation, Type type, byte[] publicKey)
        {
            if (type == null)
                throw new ArgumentNullException("type");
            if (assemblyLocation == null)
                throw new ArgumentNullException("assemblyLocation");

            _assembly = assemblyLocation;
            _types.Add(type);
            _publicKey = string.Empty;
            _publicKeyRaw = publicKey;
            if (publicKey != null)
            {
                for (int i = 0; i < publicKey.Length; ++i)
                    _publicKey += publicKey[i].ToString("x2");
            }
        }

        /// <summary>
        /// Assemblies public key if signed.
        /// </summary>
        public string PublicKey
        {
            get { return _publicKey; }
        }

        /// <summary>
        /// Assembly full path
        /// </summary>
        [Obsolete]
        public string Assembly
        {
            get { return _assembly; }
        }

        /// <summary>
        /// Location of DLL.
        /// </summary>
        public string Location
        {
            get { return _assembly; }
        }

        /// <summary>
        /// Requested types that exists in the assembly
        /// </summary>
        public List<Type> Types
        {
            get { return _types; }
        }

        /// <summary>
        /// Assembly public key in byte format.
        /// </summary>
        public byte[] PublicKeyRaw
        {
            get { return _publicKeyRaw; }
        }

        /// <summary>
        /// Add another type
        /// </summary>
        /// <param name="type"></param>
        public void Add(Type type)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            _types.Add(type);
        }
    }

}

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)

Share

About the Author

jgauffin
Founder Gauffin Interactive AB
Sweden Sweden
Founder of OneTrueError, a .NET service which captures, analyzes and provide possible solutions for exceptions.

blog | twitter

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160530.1 | Last Updated 3 Sep 2008
Article Copyright 2008 by jgauffin
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid