Module.IsDefined tells whether the specified attribute type has been applied to this module.
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 myType As Type
myType = myModule.GetType("MySimpleAttribute")
Console.WriteLine("IsDefined(MySimpleAttribute) = {0}", myModule.IsDefined(myType, False))
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