IsDefined Method

Module.IsDefined Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Determines if the specified attribute type is applied to this module.

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

'Declaration
Public Overridable Function IsDefined ( _
	attributeType As Type, _
	inherit As Boolean _
) As Boolean

Parameters

attributeType
Type: System.Type
The type of custom attribute to search for.
inherit
Type: System.Boolean
This argument is ignored for objects of this type.

Return Value

Type: System.Boolean
true if one or more instances of attributeType are applied to this module; otherwise, false.

Implements

ICustomAttributeProvider.IsDefined(Type, Boolean)

ExceptionCondition
ArgumentNullException

attributeType is Nothing.

ArgumentException

attributeType is not a Type object supplied by the runtime..

The following example defines an attribute, applies it to the example's module , and uses the IsDefined method to show that the attribute was applied to the module.


Imports System.Reflection

' Define a module-level attribute.
<Module: MySimpleAttribute("module-level")> 

Class Example
    Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
        Dim moduleArray() As [Module] = _
            [Assembly].GetExecutingAssembly().GetModules()
        Dim myModule As [Module] = moduleArray(0)
        outputBlock.Text &= _
            String.Format("IsDefined(MySimpleAttribute) = {0}" & vbLf, _
            myModule.IsDefined(GetType(MySimpleAttribute), False))
    End Sub 
End Class 

'A very simple custom attribute.
<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 

' This example produces output similar to the following:
'
'IsDefined(MySimpleAttribute) = True


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft