Click here to Skip to main content
15,886,724 members
Articles / Programming Languages / Visual Basic

Down and dirty class to retreive assembly data

Rate me:
Please Sign up or sign in to vote.
1.86/5 (4 votes)
22 Oct 2007GPL3 18.5K   49   12   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.

VB
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, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior) MMK Technologies
United States United States
I have been developing applications since 1989. My current project is SpiderLoop an ASP.NET SEO control panel. If you build asp.net applications for clients you should really check it out.

Comments and Discussions

 
GeneralMake the properites/methods static Pin
Mike Mestemaker22-Oct-07 10:22
Mike Mestemaker22-Oct-07 10:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.