zoukankan
html css js c++ java
开发c#插件步骤
开发c#插件步骤
//
1 定义插件接口,将其编译成 dll,例如:
using
System;
namespace
PluginInterface
{
public
interface
IShow
{
string
Show() ;
}
}
//
2 编写插件. 新建dll工程,并引用第一步做的dll插件,实现其接口,例如:
namespace
PluginA
{
public
class
PluginA : PluginInterface.IShow
{
public
string
Show()
{
return
"
I am plugin A
"
;
}
}
}
收集程序集:
//
3. 在指定目录下寻找Dll文件
private
void
frmMain_Load(
object
sender, System.EventArgs e)
{
//
获取Plugins目录中所有的DLL文件,并保存在combo中
try
{
string
path
=
Application.StartupPath ;
path
=
System.IO.Path.Combine(path,
"
Plugins
"
) ;
foreach
(
string
file
in
System.IO.Directory.GetFiles(path,
"
*.dll
"
))
{
this
.cmbPlugins.Items.Add(file) ;
}
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message ) ;
}
}
使用插件
private
void
btnExecute_Click(
object
sender, System.EventArgs e)
{
try
{
//
1. 获得 文件名称
string
asmFile
=
this
.cmbPlugins.Text ;
string
asmName
=
System.IO.Path.GetFileNameWithoutExtension(asmFile) ;
if
( asmFile
!=
string
.Empty )
{
//
2. 利用反射,构造DLL文件的实例
System.Reflection.Assembly asm
=
System.Reflection.Assembly.LoadFrom(asmFile) ;
//
3. 利用反射,从程序集(DLL)中,提取类,并把此类实例化
PluginInterface.IShow iShow
=
(PluginInterface.IShow)
System.Activator.CreateInstance(asm.GetType(asmName
+
"
Namespace.
"
+
asmName
+
"
Class
"
)) ;
//
4. 在主程序中使用这个类的实例
this
.label2.Text
=
iShow.Show();
}
}
catch
( Exception ex )
{
MessageBox.Show(ex.Message ) ;
}
}
查看全文
相关阅读:
W13Scan 扫描器挖掘漏洞实践
golang 单元测试框架实践
中文分词工具(LAC) 试用笔记
消息队列Rabbitmq的交换器类型
docker中使用源码方式搭建SRS流媒体服务
Ubuntu中使用Nginx+rtmp搭建流媒体直播服务
Mac下使用Pecl安装PHP的Swoole扩展实践
Ubuntu中使用Nginx+rtmp模块搭建流媒体视频点播服务
安卓开发开发规范手册V1.0
【数据库技术】MySql 45讲整合
原文地址:https://www.cnblogs.com/tonybinlj/p/1297904.html
最新文章
innodb动态内存管理
Innodb Buffer Pool内部结构
list的常见操作以及算法的时间复杂度
InnoDB MVCC浅谈
快速排序VS堆排序
算法.给定数为数组中2个元素的之和,求出数组的下标
算法.链表反转
算法.List链表加法
快速排序/堆排序
C实现heap堆排序
热门文章
代码模版
博客园实现Markdown代码框复制功能
Python快速创建HTTP服务器
MarkDown折叠语法
AWS破解EC2 key pair
day2逻辑运算作业详解
3.body标签中相关标签2
2.body标签中的相关标签1
1.HTML介绍和规范
W13Scan 漏洞扫描器之XSS插件模块编写示例
Copyright © 2011-2022 走看看