C#实现插件式架构

1.定义插件接口,将其编译为DLL

namespace PluginInterface
{
    public interface IShow
    {
        string show();
    }
}

2 .编写插件,引用上面的DLL,实现上面定义的接口,也编译为DLL

//插件A

namespace PluginInterface
{
    public class PluginA:IShow
    {
        public string show()
        {
            return "插件A";
        }

    }
}

//插件B

namespace PluginB
{
    public class PluginB:IShow
    {

        public string show()
        {
            return "插件B";
        }

    }
}

 

3,在程序中使用插件,需要引用定义插件接口的DLL

namespace testPlugin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //查找所有的插件的路径
        private List FindPlugin()
        {
            List PluginPaths = new List();
           

你可能感兴趣的:(c#技巧,c#,string,assembly,null,exception,path)