Obtenir les informations de l'Assembly qui ne sont pas disponibles par la classe 'Application'

Contenu du snippet

Imports System.Reflection
'Permet d'obtenir les informations de l'Assembly
'qui ne sont pas disponibles par la classe 'Application'
'
Module Assembly_Informations
    Public AssemblyTitle As String
    Public AssemblyDescription As String = ""
    Public AssemblyCompany As String = ""
    Public AssemblyProduct As String = ""
    Public AssemblyCopyright As String = ""
    Public AssemblyTrademark As String = ""
    Public AssemblyGuid As String = ""
    Public AssemblyVersion As String = ""
    Public AssemblyFileVersion As String = ""
    Private m_MyAssembly As [Assembly]
    Private Sub GetAssemblyValues()
        Dim lAttrib As Attribute
        Dim lTitle_Attrib As AssemblyTitleAttribute
        Dim lProduct_Attrib As AssemblyProductAttribute
        Dim lDescription_Attrib As AssemblyDescriptionAttribute
        Dim lCompany_Attrib As AssemblyCompanyAttribute
        Dim lCopyright_Attrib As AssemblyCopyrightAttribute
        Dim lTrademark_Attrib As AssemblyTrademarkAttribute
        Dim lVersion_Attrib As AssemblyVersionAttribute
        Dim lFileVersion_Attrib As AssemblyFileVersionAttribute
        Dim lGUID_Attrib As System.Runtime.InteropServices.GuidAttribute
        m_MyAssembly = [Assembly].GetExecutingAssembly()
        If m_MyAssembly.IsDefined(GetType(System.Runtime.InteropServices.GuidAttribute), True) Then
            lAttrib = Attribute.GetCustomAttribute(m_MyAssembly, GetType(System.Runtime.InteropServices.GuidAttribute))
            lGUID_Attrib = DirectCast(lAttrib, System.Runtime.InteropServices.GuidAttribute)
            AssemblyGuid = lGUID_Attrib.Value.ToString
        End If
        If m_MyAssembly.IsDefined(GetType(AssemblyTitleAttribute), True) Then
            lAttrib = Attribute.GetCustomAttribute(m_MyAssembly, GetType(AssemblyTitleAttribute))
            lTitle_Attrib = DirectCast(lAttrib, AssemblyTitleAttribute)
            AssemblyTitle = lTitle_Attrib.Title
        End If
        If m_MyAssembly.IsDefined(GetType(AssemblyDescriptionAttribute), True) Then
            lAttrib = Attribute.GetCustomAttribute(m_MyAssembly, GetType(AssemblyDescriptionAttribute))
            lDescription_Attrib = DirectCast(lAttrib, AssemblyDescriptionAttribute)
            AssemblyDescription = lDescription_Attrib.Description
        End If
        If m_MyAssembly.IsDefined(GetType(AssemblyCompanyAttribute), True) Then
            lAttrib = Attribute.GetCustomAttribute(m_MyAssembly, GetType(AssemblyCompanyAttribute))
            lCompany_Attrib = DirectCast(lAttrib, AssemblyCompanyAttribute)
            AssemblyCompany = lCompany_Attrib.Company
        Else
            AssemblyCompany = Application.CompanyName
        End If
        If m_MyAssembly.IsDefined(GetType(AssemblyProductAttribute), True) Then
            lAttrib = Attribute.GetCustomAttribute(m_MyAssembly, GetType(AssemblyProductAttribute))
            lProduct_Attrib = DirectCast(lAttrib, AssemblyProductAttribute)
            AssemblyProduct = lProduct_Attrib.Product
        Else
            AssemblyProduct = Application.ProductName
        End If
        If m_MyAssembly.IsDefined(GetType(AssemblyCopyrightAttribute), True) Then
            lAttrib = Attribute.GetCustomAttribute(m_MyAssembly, GetType(AssemblyCopyrightAttribute))
            lCopyright_Attrib = DirectCast(lAttrib, AssemblyCopyrightAttribute)
            AssemblyCopyright = lCopyright_Attrib.Copyright
        End If
        If m_MyAssembly.IsDefined(GetType(AssemblyTrademarkAttribute), True) Then
            lAttrib = Attribute.GetCustomAttribute(m_MyAssembly, GetType(AssemblyTrademarkAttribute))
            lTrademark_Attrib = DirectCast(lAttrib, AssemblyTrademarkAttribute)
            AssemblyTrademark = lTrademark_Attrib.Trademark
        End If
        If m_MyAssembly.IsDefined(GetType(AssemblyVersionAttribute), True) Then
            lAttrib = Attribute.GetCustomAttribute(m_MyAssembly, GetType(AssemblyVersionAttribute))
            lVersion_Attrib = DirectCast(lAttrib, AssemblyVersionAttribute)
            AssemblyVersion = lVersion_Attrib.Version.ToString
        Else
            AssemblyVersion = m_MyAssembly.GetName().Version.ToString 
        End If
        If m_MyAssembly.IsDefined(GetType(AssemblyFileVersionAttribute), True) Then
            lAttrib = Attribute.GetCustomAttribute(m_MyAssembly, GetType(AssemblyFileVersionAttribute))
            lFileVersion_Attrib = DirectCast(lAttrib, AssemblyFileVersionAttribute)
            AssemblyFileVersion = lFileVersion_Attrib.Version.ToString
        End If
    End Sub
End Module


Compatibilité : VB 2008

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.