C#讀取DLL文件獲取所有類


說明

調用Web.dll 文件,獲取其中的所有的WebService
參考

流程

使用LoadFile加載外部dll文件

重點:注意的是,如果查看的對象是外部的DLL,一定要把DLL復制到項目的調試文件夾Debug下。
<add key="PHPWebdll" value="E:\WebIIS\PHP_Publish\bin\BF.Web.dll"/>
//從dll文件中獲取Assembly對象
Assembly assembly = Assembly.LoadFile(System.Configuration.ConfigurationManager.AppSettings["PHPWebdll"].ToString());
//獲取所有的類
Type[] types = assembly.GetExportedTypes();

將 Web.dll相關的dll文件全部復制到程序的調試文件夾debug下面

從E:\WorkDirectory\PublicHealthPlatform\PublicHealthPlatform\BF.Web\bin\
到E:\GitHub\CustomCommonSoft\CommonSoft\bin\Debug\

獲取所有的WebService

思路:命名空間以"BF.Web.WebService"開頭,繼承"System.Web.Services.WebService"類
string sDefaultNameSpace = "BF.Web.WebService";
if (!string.IsNullOrEmpty(item.Namespace) && item.Namespace.StartsWith(sDefaultNameSpace) && item.BaseType.FullName == "System.Web.Services.WebService")
{
string sClassName=item.Name;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM