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;
          }
        }
      }

    }

  • 相关阅读:
    Spring包的依赖关系以及提供下载
    正则
    Spring征服数据库
    Java之多线程同步基础
    Java之多线程优先级基础
    ColorMatrixFilter色彩矩阵滤镜
    AS3.0 位图翻转、旋转
    AS3.0 自定义右键菜单类
    精确选择识别png图片有像素的区域
    AS3动画效果常用公式
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14040090.html
Copyright © 2011-2022 走看看