Module.GetCustomAttributes gets custom attributes of the specified type.
Imports System
Imports System.Reflection
<Module: MySimpleAttribute("module-level")>
Class MyMainClass
Shared Sub Main()
Dim moduleArray() As [Module]
moduleArray = [Assembly].GetExecutingAssembly().GetModules(False)
Dim myModule As [Module] = moduleArray(0)
Dim attributes() As Object
attributes = myModule.GetCustomAttributes(myModule.GetType("MySimpleAttribute", _
False, False), True)
Dim o As [Object]
For Each o In attributes
Console.WriteLine("Found this attribute on myModule: {0}", o.ToString())
Next o
End Sub
End Class
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Module)> _
Public Class MySimpleAttribute
Inherits Attribute
Private name As String
Public Sub New(ByVal newName As String)
name = newName
End Sub
End Class
Related examples in the same category