Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Down and dirty class to retreive assembly data

0.00/5 (No votes)
22 Oct 2007 1  
Inheritable class for retreving assembly data using VB.NET and .NET Framework 2.0.

Introduction

This is just a simple class to retrieve assembly data from the current application using VB.NET. It will return each of the assembly variables as a string.

Background

It seems that most of the code snippets I could find elsewhere just simply did not work or had lots of complicated forms that I did not need. This one you can just import and it is done.

Using the code

Copy and compile and that's about it, or just download my example and reference the 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

History

  • Version 1.0: No changes yet.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here