Attribute.IsDefined Method (Module, Type, Boolean)
Determines whether any custom attributes are applied to a module. Parameters specify the module, the type of the custom attribute to search for, and an ignored search option.
Assembly: mscorlib (in mscorlib.dll)
Public Shared Function IsDefined ( element As Module, attributeType As Type, inherit As Boolean ) As Boolean
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.
- inherit
-
Type:
System.Boolean
This parameter is ignored, and does not affect the operation of this method.
Return Value
Type: System.Booleantrue if a custom attribute of type attributeType is applied to element; otherwise, false.
| Exception | Condition |
|---|---|
| ArgumentNullException | element or attributeType is null. |
| ArgumentException | attributeType is not derived from Attribute. |
This method ignores the inherit parameter and does not search the ancestors of element 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.
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0