欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#關(guān)于反射加載的問題

 更新時間:2011年07月11日 22:47:14   作者:  
C#關(guān)于反射加載的問題,需要的朋友可以參考下。
三個程序集:
主程序集:BaseApp.exe
接口程序集:IBaseApplication
插件程序集:TestAttri
=======================================================================================
在接口程序中:
接口:IApp
屬性定義:ModuleAttribute
復(fù)制代碼 代碼如下:

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類中標(biāo)識如下
復(fù)制代碼 代碼如下:

[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 = "")]

有兩個模塊分別是以下
復(fù)制代碼 代碼如下:

namespace TestAttri
{
public partial class UserControl1 : UserControl, IApp
{
……
}
}
namespace TestAttri
{
public partial class UserControl2 : UserControl, IApp
{
……
}
}

=================================================================================================
在主程序集中:
將插件放至到:Application.StartupPath + "\\Plus"
引用了接口程序集“IBaseApplication”
復(fù)制代碼 代碼如下:

/// <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)
{//無法識別兩個模塊的接口。
}
}
}
}

相關(guān)文章

  • C#如何操作Excel數(shù)據(jù)透視表

    C#如何操作Excel數(shù)據(jù)透視表

    這篇文章主要為大家詳細(xì)介紹了C#如何操作Excel數(shù)據(jù)透視表, 創(chuàng)建透視表、設(shè)置行折疊、展開等操作,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • C#使用Gembox.SpreadSheet向Excel寫入數(shù)據(jù)及圖表的實(shí)例

    C#使用Gembox.SpreadSheet向Excel寫入數(shù)據(jù)及圖表的實(shí)例

    下面小編就為大家分享一篇C#使用Gembox.SpreadSheet向Excel寫入數(shù)據(jù)及圖表的實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • C# WebApi CORS跨域問題解決方案

    C# WebApi CORS跨域問題解決方案

    本篇文章主要介紹了C# WebApi CORS跨域問題解決方案,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • C#中數(shù)據(jù)類型的轉(zhuǎn)換介紹

    C#中數(shù)據(jù)類型的轉(zhuǎn)換介紹

    大家好,本篇文章主要講的是C#中數(shù)據(jù)類型的轉(zhuǎn)換介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2022-01-01
  • C#使用DeflateStream解壓縮數(shù)據(jù)文件的方法

    C#使用DeflateStream解壓縮數(shù)據(jù)文件的方法

    這篇文章主要介紹了C#使用DeflateStream解壓縮數(shù)據(jù)文件的方法,較為詳細(xì)的分析了DeflateStream方法對文件進(jìn)行壓縮及解壓縮的步驟與技巧,需要的朋友可以參考下
    2015-04-04
  • C# winform點(diǎn)擊生成二維碼實(shí)例代碼

    C# winform點(diǎn)擊生成二維碼實(shí)例代碼

    這篇文章主要介紹了 C# winform點(diǎn)擊生成二維碼實(shí)例代碼,需要的朋友可以參考下
    2017-04-04
  • c# 從IE瀏覽器獲取當(dāng)前頁面的內(nèi)容

    c# 從IE瀏覽器獲取當(dāng)前頁面的內(nèi)容

    從IE瀏覽器獲取當(dāng)前頁面內(nèi)容可能有多種方式,今天我所介紹的是其中一種方法?;驹恚寒?dāng)鼠標(biāo)點(diǎn)擊當(dāng)前IE頁面時,獲取鼠標(biāo)的坐標(biāo)位置,根據(jù)鼠標(biāo)位置獲取當(dāng)前頁面的句柄,然后根據(jù)句柄,調(diào)用win32的東西進(jìn)而獲取頁面內(nèi)容。感興趣的朋友可以參考下本文
    2021-06-06
  • C#開發(fā)交互式命令行應(yīng)用示例

    C#開發(fā)交互式命令行應(yīng)用示例

    這篇文章主要為大家介紹了C#開發(fā)交互式命令行應(yīng)用示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • C#中Backgroundworker與Thread的區(qū)別

    C#中Backgroundworker與Thread的區(qū)別

    本文主要介紹了C#中Backgroundworker與Thread的區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • C#繪制實(shí)時曲線的方法

    C#繪制實(shí)時曲線的方法

    這篇文章主要為大家詳細(xì)介紹了C#繪制實(shí)時曲線的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02

最新評論