Assembly 读取程序集信息

1.当程序集发布成.Dll 后,我们怎么才能读取其产品名称呢;比如我想知道我加载的这个数据集叫什么;

2.我们可以通过Assembly 类来对 类AssemblyInfo.cs 进行 操作;


3.AssemblyInfo.cs 在文件夹properties 下,每个程序都有,它记录着程序集的许多相关信息;

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的常规信息通过下列属性集
// 控制。更改这些属性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("RongTongProtocol")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("产品名称")]
[assembly: AssemblyCopyright("版权所有 (C)  2006")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

............

4.我们在主程序中调用它:

         '程序集文件路径
          Dim pPath As String = AppDomain.CurrentDomain.BaseDirectory + "\Plugins"
         '取得该文件夹下所有文件路径
        Dim strFunctionFiles As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = _
            My.Computer.FileSystem.GetFiles(pPath)
         '遍历所有文件(数据集)
        For Each pth As String In strFunctionFiles
            '取得文件
            Dim pthInfo As FileInfo = My.Computer.FileSystem.GetFileInfo(pth)
            '取得文件名
            'Dim pathName As String = Path.GetFileName(pth) '取得数据集的产品名称
            '加载程序集相关信息
            Dim myAsembly As System.Reflection.Assembly  = System.Reflection.Assembly.LoadFrom(pth)
            '取得产品信息
            Dim myAttribute As System.Attribute _
                            = System.Reflection.AssemblyProductAttribute.GetCustomAttribute(myAsembly, GetType(System.Reflection.AssemblyProductAttribute), True)
            'system.Attribute.
           '取得产品名称
            Dim strNameSpace As String = myProductAttribute.Product
Next

5.OK....数据取出来了...同理可以读取其它信息...甚至自定义信息;我也没尝试过,有兴趣的朋友可尝试尝试.最好给予回复互相学习.呵呵....上面代码相对简单我就不写成C#了.如有需要可留言.

转载于:https://www.cnblogs.com/ganyuansong/archive/2007/05/22/755332.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值