Tipp 0050 Assembly-Information auslesen
Autor/Einsender:
Datum:
  Michael Werner
24.07.2004
Entwicklungsumgebung:   VB.Net 2003
Framework:   1.1
Mit den Assembly-Klassen im Namespace System.Reflection können die Informationen des Assembly, die in der Datei AssemblyInfo.vb festgehalten sind, ausgelesen werden. In diesem Tipp wurde ein Klasse mit ReadOnly-Properties erstellt, die in einer About-Form diese Daten ausliest.
 
Imports System.Reflection

Namespace Michaels
  Public Class ReadAssembly
    Private myType As Type

    Public Sub New()
      myType = GetType(Form1)
    End Sub

    Public ReadOnly Property Name() As String
      Get
        Return myType.Assembly.GetName.Name.ToString()
      End Get
    End Property

    Public ReadOnly Property FullName() As String
      Get
        Return myType.Assembly.GetName.FullName.ToString()
      End Get
    End Property

    Public ReadOnly Property CodeBase() As String
      Get
        Return myType.Assembly.CodeBase
      End Get
    End Property

    Public ReadOnly Property Copyright() As String
      Get
        Dim at As Type = GetType(AssemblyCopyrightAttribute)
        Dim r() As Object = _
                 myType.Assembly.GetCustomAttributes(at, False)
        Dim ct As AssemblyCopyrightAttribute = _
                 CType(r(0), AssemblyCopyrightAttribute)
        Return ct.Copyright
      End Get
    End Property

    Public ReadOnly Property Company() As String
      Get
        Dim at As Type = GetType(AssemblyCompanyAttribute)
        Dim r() As Object = _
                 myType.Assembly.GetCustomAttributes(at, False)
        Dim ct As AssemblyCompanyAttribute = _
                 CType(r(0), AssemblyCompanyAttribute)
        Return ct.Company
      End Get
    End Property

    Public ReadOnly Property Description() As String
      Get
        Dim at As Type = GetType(AssemblyDescriptionAttribute)
        Dim r() As Object = _
                 myType.Assembly.GetCustomAttributes(at, False)
        Dim da As AssemblyDescriptionAttribute = _
                 CType(r(0), AssemblyDescriptionAttribute)
        Return da.Description
      End Get
    End Property

    Public ReadOnly Property Product() As String
      Get
        Dim at As Type = GetType(AssemblyProductAttribute)
        Dim r() As Object = _
                 myType.Assembly.GetCustomAttributes(at, False)
        Dim pt As AssemblyProductAttribute = _
                 CType(r(0), AssemblyProductAttribute)
        Return pt.Product
      End Get
    End Property

    Public ReadOnly Property Title() As String
      Get
        Dim at As Type = GetType(AssemblyTitleAttribute)
        Dim r() As Object = _
                 myType.Assembly.GetCustomAttributes(at, False)
        Dim ta As AssemblyTitleAttribute = _
                 CType(r(0), AssemblyTitleAttribute)
        Return ta.Title
      End Get
    End Property

    Public ReadOnly Property Version() As String
      Get
        Return myType.Assembly.GetName.Version.ToString()
      End Get
    End Property
  End Class
End Namespace
 
Weitere Links zum Thema
Dateiattribute lesen und setzen
MAC-Adresse auslesen
Systemeinstellungen auslesen

Windows-Version
98/SE
ME
NT
2000
XP
Vista
Win 7


Download  (10,7 kB) Downloads bisher: [ 508 ]

Vorheriger Tipp Zum Seitenanfang Nächster Tipp

Startseite | Tipps | Projekte | Tutorials | Bücherecke | VB-/VBA-Tipps | API-Referenz | Komponenten | VB.Net-Forum | VB/VBA-Forum | DirectX-Forum | Foren-Archiv | DirectX | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum

Seite empfehlen Bug-Report
Letzte Aktualisierung: Sonntag, 22. Januar 2012