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 ) ;
}
}
查看全文
相关阅读:
【转+补充】在OpenCV for Android 2.4.5中使用SURF(nonfree module)
Delphi StarOffice Framework Beta 1.0 发布
Angular ngIf相关问题
angularjs文档下载
公众号微信支付开发
公众号第三方平台开发 教程六 代公众号使用JS SDK说明
公众号第三方平台开发 教程五 代公众号处理消息和事件
公众号第三方平台开发 教程四 代公众号发起网页授权说明
公众号第三方平台开发 教程三 微信公众号授权第三方平台
公众号第三方平台开发 教程二 component_verify_ticket和accessToken的获取
原文地址:https://www.cnblogs.com/tonybinlj/p/1297904.html
最新文章
作业调度模拟程序
实验一 认识DOS
操作系统历史PPT
0909 对操作系统的认识
c#获取时间
c#常见的正则表达式
OptionalFeatures
转载:npm 安装React Devtools调试工具
转载:最常被遗忘的 Web 性能优化:浏览器缓存
使用http.sys,让delphi的多层服务真的飞起来【第二部】
热门文章
转载 winsock、ws2_32、WinInet、WinHttp 对比
转载:TClientDataSet用法详解
Delphi AnsiString 与 PAnsiChar
【心得】关于删除结构体动态数组指定项的正确方法
【近况】杂事+分享阿里大于短信验证码的完整实现代码
【转】编译Lua5.3.0的iOS静态库
【Asphyre引擎】发布了新版本V101
【Asphyre引擎】关于AsphyreTypes中OverlapRect的改动,都是泪啊!!!
【Asphyre引擎】Asphyre时隔3年,更名为PXL,全平台支持!
Delphi又要换东家了
Copyright © 2011-2022 走看看