Mega Code Archive

 
Categories / VB.Net Tutorial / Reflection
 

IsDefined taking an Assembly as a parameter

Imports System Imports System.Reflection Imports Microsoft.VisualBasic <Assembly: AssemblyDescription("A sample description")>  Module DemoModule     Sub Main()         Dim assy As System.Reflection.Assembly = GetType(DemoModule).Assembly         Dim assyName As String = assy.GetName().Name         If Attribute.IsDefined(assy, GetType(AssemblyDescriptionAttribute)) Then             Console.WriteLine(assyName)             Dim attr As Attribute = Attribute.GetCustomAttribute(assy, GetType(AssemblyDescriptionAttribute))             If Not attr Is Nothing And TypeOf attr Is AssemblyDescriptionAttribute Then                 Dim adAttr As AssemblyDescriptionAttribute = CType(attr, AssemblyDescriptionAttribute)                 Console.WriteLine(adAttr.Description)             Else                 Console.WriteLine("The description could not be retrieved.")             End If         End If     End Sub End Module