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;
}
posted @ 2020-04-20 21:51  我有我奥妙  阅读(3156)  评论(2编辑  收藏  举报