麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > C# > 正文

C#關于反射加載的問題

2020-01-24 03:43:05
字體:
來源:轉載
供稿:網友
三個程序集:
主程序集: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 + "http://Plus"
引用了接口程序集“IBaseApplication”
復制代碼 代碼如下:

/// <summary>
/// 獲取插件文件名稱
/// </summary>
/// <returns></returns>
public string[] GetPlusFiles()
{
return System.IO.Directory.GetFiles(Application.StartupPath + "http://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)
{//無法識別兩個模塊的接口。
}
}
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久久www视频 | 成人在线视频精品 | 美女污污在线观看 | 日韩av片网站| 欧美视频网 | 91午夜在线观看 | 国产一区二区三区四区精 | 国产免费传媒av片在线 | 精品一区二区久久久久久久网精 | 久久伊人精品视频 | 欧美一级黄色免费看 | 久久精品亚洲精品国产欧美kt∨ | 性猛交ⅹxxx乱巴西 在线播放中文 | 亚洲成人久久精品 | 福利在线影院 | 91看片片 | 午夜精品久久久久久久久久久久久蜜桃 | 欧美大逼网 | 午夜在线视频一区二区三区 | 中文区永久区 | 最新欧美精品一区二区三区 | 九九热视频这里只有精品 | 成人性生活视频在线观看 | 九九热免费在线观看 | 一级电影在线免费观看 | 国产资源在线观看视频 | 国产91av视频| 舌头伸进添的我好爽高潮网站 | 国产精品区一区二区三区 | 毛片免费一区二区三区 | 91女上位 在线播放 性欧美日本 | 一分钟免费观看完整版电影 | 久啪视频 | 久久久久久久一区二区三区 | 久久2019中文字幕 | 亚洲成人精品一区二区 | xxxxhd86日本护士hd | 中文区永久区 | 国产精品久久久久影院老司 | 护士hd老师fre0性xxx | 羞羞视频免费观看网站 |