三个程序集:
主程序集:baseapp.exe
接口程序集:ibaseapplication
插件程序集:testattri
=======================================================================================
在接口程序中:
接口:iapp
属性定义:moduleattribute
public interface iapp : imothed
{
void parentform(iapp frm);
}
namespace ibaseapplication.attributes
{
[attributeusage(attributetargets.assembly | attributetargets.interface | attributetargets.field | attributetargets.method | attributetargets.class | attributetargets.property, allowmultiple = true, inherited = false)]
public class moduleattribute : attribute
{
public string idname { get; set; }
public string modulename { get; set; }
public type moduletype { get; set; }
//public string asmname { get; set; }
//public string classname { get; set; }
public string description { get; set; }
}
}
在插件程序集中:
在该插件程序集中的assemblyinfo类中标识如下
[assembly: ibaseapplication.attributes.module(moduletype = typeof(usercontrol1), idname = "be4d9a5b-0455-4e9d-a255-25122b80bef1-usercontrol1", modulename = "usercontrol1", description = "")]
[assembly: ibaseapplication.attributes.module(moduletype = typeof(usercontrol2), idname = "be4d9a5b-0455-4e9d-a255-25122b80bef1-usercontrol2", modulename = "usercontrol2", description = "")]
有两个模块分别是以下
namespace testattri
{
public partial class usercontrol1 : usercontrol, iapp
{
……
}
}
namespace testattri
{
public partial class usercontrol2 : usercontrol, iapp
{
……
}
}
=================================================================================================
在主程序集中:
将插件放至到:application.startuppath + "\\plus"
引用了接口程序集“ibaseapplication”
/// <summary>
/// 获取插件文件名称
/// </summary>
/// <returns></returns>
public string[] getplusfiles()
{
return system.io.directory.getfiles(application.startuppath + "\\plus");
}
/// <summary>
/// 加载插件
/// </summary>
public void loadplufiles()
{
string[] files = getplusfiles();
assembly assembly = assembly.getcallingassembly();
foreach (string file in files)
{
moduleattribute[] attributes = assembly.loadfile(file).getcustomattributes(typeof(moduleattribute), false) as moduleattribute[];
foreach (moduleattribute attribute in attributes)
{
string m = attribute.moduletype.fullname;
string m1 = attribute.moduletype.assembly.getname().name;
object obj = activator.createinstance(attribute.moduletype);
if (obj is iapp)
{//无法识别两个模块的接口。
}
}
}
}
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
C#实现猜数字游戏
本文实例为大家分享了c#实现猜数字游戏具体代码,供大家参考,具体内容如下给定一个0-100的随机数字猜其大小题目样式:电脑产生一个0到100之间的随机数字,并且...
[阅读全文]
-
-
C# 可空类型的具体使用
在项目中我们经常会遇到可为空类型,那么到底什么是可为空类型呢?下面我们将从4个方面为大家剖析。1、可空类型基础知识顾名思义,可空类型指的就是某个对象类型可以为空...
[阅读全文]
-
-
-
C#实现猜数字小游戏
本文实例为大家分享了c#实现猜数字小游戏的具体代码,供大家参考,具体内容如下效果如图:代码:using system;using system.collecti...
[阅读全文]
-
-
C#实现简单俄罗斯方块
最近在看《.net游戏编程入门经典 c#篇》 第一章介绍了如何制作俄罗斯方块,自己试了试按照书上的步骤,可算是完成了。于是写下这篇文章留作纪念。1.类的设计在充...
[阅读全文]
-
网友评论