Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
IsDefined Method

Module.IsDefined Method

Returns a value that indicates whether the specified attribute type has been 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 test 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 have been 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. For example, attributeType is a TypeBuilder object.

The following example demonstrates a use of the IsDefined method.

Imports System.Reflection

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

'Define a module-level attribute. 
Namespace ReflectionModule_Examples
    Class MyMainClass
        Shared Sub Main()
            Dim moduleArray() As [Module]

            moduleArray = GetType(MyMainClass).Assembly.GetModules(False)

            'In a simple project with only one module, the module at index 
            ' 0 will be the module containing these classes. 
            Dim myModule As [Module] = moduleArray(0)

            Dim myType As Type
            myType = myModule.GetType("ReflectionModule_Examples.MySimpleAttribute")
            Console.WriteLine("IsDefined(MySimpleAttribute) = {0}", myModule.IsDefined(myType, False))
        End Sub 'Main
    End Class 'MyMainClass

    '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 'New 
    End Class 'MySimpleAttribute
End Namespace 'ReflectionModule_Examples

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8
Show:
© 2015 Microsoft