实用的类,用于检索程序集数据
一个可继承的类,用于使用VB.NET和.NET Framework 2.0检索程序集数据。
引言
这是一个简单的类,用于使用VB.NET从当前应用程序检索程序集数据。它将把每个程序集变量作为字符串返回。
背景
我发现大多数其他地方的代码片段要么根本无法工作,要么有很多我不需要的复杂形式。这个你可以直接导入并使用。
使用代码
复制并编译即可,或者直接下载我的示例并引用DLL。
Imports SYR = System.Reflection
Public Class GetAssembly
Private assembType As System.Reflection.Assembly
Public Sub New()
assembType = System.Reflection.Assembly.GetExecutingAssembly
End Sub
Public ReadOnly Property TName() As String
Get
Return assembType.GetName.ToString()
End Get
End Property
Public ReadOnly Property TFullName() As String
Get
Return assembType.GetName.FullName.ToString()
End Get
End Property
Public ReadOnly Property CodeBase() As String
Get
Return assembType.CodeBase.ToString()
End Get
End Property
Public ReadOnly Property Copyright() As String
Get
Dim attype As Type = GetType(SYR.AssemblyCopyrightAttribute)
Dim atr() As Object = assembType.GetCustomAttributes(attype, False)
Dim ct As SYR.AssemblyCopyrightAttribute = _
CType(atr(0), SYR.AssemblyCopyrightAttribute)
Return ct.Copyright
End Get
End Property
Public ReadOnly Property Company() As String
Get
Dim attype As Type = GetType(SYR.AssemblyCompanyAttribute)
Dim atr() As Object = assembType.GetCustomAttributes(attype, False)
Dim ct As SYR.AssemblyCompanyAttribute = CType(atr(0), SYR.AssemblyCompanyAttribute)
Return ct.Company
End Get
End Property
Public ReadOnly Property Description() As String
Get
Dim attype As Type = GetType(SYR.AssemblyDescriptionAttribute)
Dim atr() As Object = assembType.GetCustomAttributes(attype, False)
Dim da As SYR.AssemblyDescriptionAttribute = _
CType(atr(0), SYR.AssemblyDescriptionAttribute)
Return da.Description
End Get
End Property
Public ReadOnly Property Product() As String
Get
Dim attype As Type = GetType(SYR.AssemblyProductAttribute)
Dim atr() As Object = assembType.GetCustomAttributes(attype, False)
Dim pt As SYR.AssemblyProductAttribute = _
CType(atr(0), SYR.AssemblyProductAttribute)
Return pt.Product
End Get
End Property
Public ReadOnly Property Title() As String
Get
Dim attype As Type = GetType(SYR.AssemblyTitleAttribute)
Dim atr() As Object = assembType.GetCustomAttributes(attype, False)
Dim ta As SYR.AssemblyTitleAttribute = CType(atr(0), SYR.AssemblyTitleAttribute)
Return ta.Title
End Get
End Property
Public ReadOnly Property Version() As String
Get
Return assembType.GetName.Version.ToString()
End Get
End Property
End Class
历史
- 版本 1.0:尚未进行更改。