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 ) ;
}
}
查看全文
相关阅读:
Myeclipse如何使用自带git工具向远程仓库提交代码
myEclipse配置java版本(环境、项目、编译)
新搭建项目时需要修改的内容
干锅土豆
SpringMVC MongoDB之“基本文档查询(Query、BasicQuery)”
史上最全web.xml配置文件元素详解
Web.xml配置详解之context-param
史上最全的maven的pom.xml文件详解
MongoDB 进阶模式设计
备忘整理
原文地址:https://www.cnblogs.com/tonybinlj/p/1297904.html
最新文章
unity模型法线反转问题
3D max模型导入unity 3D中注意事项
shader实例(二十二)TexGen-球面贴图SphereMap
DirectX实现球面纹理映射
全景图片(鱼眼)的平面映射矫正
TRANSFORM_TEX是做什么的
Unity5.0 EventSystem事件系统的详细说明
hdu2048
hdu2047
hdu2046
热门文章
hdu2045
hdu2044
I.幸运大奖
H.所有情况的和
E.集合中的质数
D.轰炸区最优选取
E.数圈圈
git填坑笔记
git branch用法总结
你可能不知道的git clean
Copyright © 2011-2022 走看看