Export (0) Print
Expand All

Attribute.IsDefined Method (Module, Type)

Determines whether any custom attributes of a specified type are applied to a module. Parameters specify the module, and the type of the custom attribute to search for.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public Shared Function IsDefined ( _
	element As Module, _
	attributeType As Type _
) As Boolean
'Usage
Dim element As [Module]
Dim attributeType As Type 
Dim returnValue As Boolean 

returnValue = Attribute.IsDefined(element, _
	attributeType)

Parameters

element
Type: System.Reflection.Module

An object derived from the Module class that describes a portable executable file.

attributeType
Type: System.Type

The type, or a base type, of the custom attribute to search for.

Return Value

Type: System.Boolean
true if a custom attribute of type attributeType is applied to element; otherwise, false.

ExceptionCondition
ArgumentNullException

element or attributeType is Nothing.

ArgumentException

attributeType is not derived from Attribute.

The ancestors of element are not searched for custom attributes.

The following code example illustrates the use of IsDefined, taking a Module as a parameter.

Imports System
Imports System.Reflection
Imports System.Diagnostics

' Add the Debuggable attribute to the module.
<Module: Debuggable(True, False)> 

Module DemoModule
    Sub Main()
        ' Get the module type information to access its metadata. 
        Dim modType As Type = GetType(DemoModule)
        ' See if the Debuggable attribute is defined. 
        Dim isDef As Boolean = Attribute.IsDefined(modType.Module, _
                               GetType(DebuggableAttribute))
        Dim strDef As String 
        If isDef = True Then
            strDef = "is" 
        Else
            strDef = "is not" 
        End If 
        ' Display the result
        Console.WriteLine("The debuggable attribute {0} defined for " & _
                          "module {1}.", strDef, modType.Name)
        ' If the attribute is defined, display the JIT settings. 
        If isDef = True Then 
            ' Retrieve the attribute itself. 
            Dim attr As Attribute = _
                Attribute.GetCustomAttribute(modType.Module, _
                GetType(DebuggableAttribute))
            If Not attr Is Nothing And TypeOf attr Is DebuggableAttribute Then 
                Dim dbgAttr As DebuggableAttribute = _
                    CType(attr, DebuggableAttribute)
                Console.WriteLine("JITTrackingEnabled is {0}.", _
                    dbgAttr.IsJITTrackingEnabled.ToString())
                Console.WriteLine("JITOptimizerDisabled is {0}.", _
                    dbgAttr.IsJITOptimizerDisabled.ToString())
            Else
                Console.WriteLine("The Debuggable attribute could " & _
                                  "not be retrieved.")
            End If 
        End If 
    End Sub 
End Module 

' Output: 
' The debuggable attribute is defined for module DemoModule. 
' JITTrackingEnabled is True. 
' JITOptimizerDisabled is False.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft