zoukankan      html  css  js  c++  java
  • C# 插件编写

    //加载插件
    private void LoadPlugins()
    {
      string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "addons");

      //搜索该目录下的所有的程序集文件,这里就只搜索*.dll文件
      string[] dlls = Directory.GetFiles(path, "*.dll");

      //动态加载每个dll 文件
      foreach (string dllPath in dlls)
      {
        //加载每个程序集
        Assembly assembly = Assembly.LoadFile(dllPath);

        //需要一个接口来进行约定
        Type typeIEditor = typeof(IEditor);

        //获取当前加载的程序集中的所有的public类型
        Type[] types = assembly.GetExportedTypes();

        //遍历判断哪个类型实现了该接口
        foreach (Type userType in types)
        {
          //判断这个类型必须是实现了IEditor接口的类型,并且该类型必须不是抽象的。
          if (typeIEditor.IsAssignableFrom(userType) && !userType.IsAbstract)
          {
            IEditor plugin = (IEditor)Activator.CreateInstance(userType);

            //把插件名称加载到菜单栏上
            //Add()方法的返回值就是刚刚增加的菜单项
            ToolStripItem tsi = tsmiFormat.DropDownItems.Add(plugin.Name);
            //为该菜单项增加一个单击事件
            tsi.Click += new EventHandler(tsi_Click);
            tsi.Tag = plugin;
          }
        }
      }

    }

  • 相关阅读:
    基于最大最小距离的分类数目上限K确定的聚类方法
    diff函数(matlab)
    CreateThread线程函数
    套接字基础
    基于TCP套接字实现的简单Demo
    使用httpwatch抓包
    TLV----Demo讲解
    关于位图边缘的检测定位
    从txt中读入数据到数组中(fscanf)
    C语言运算符的优先级
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14040090.html
Copyright © 2011-2022 走看看