Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Attribute.GetCustomAttributes Method (Module, Type, Boolean)

Retrieves an array of the custom attributes applied to a module. Parameters specify the module, the type of the custom attribute to search for, and an ignored search option.

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

Public Shared Function GetCustomAttributes ( _
	element As Module, _
	attributeType As Type, _
	inherit As Boolean _
) As Attribute()


Type: System.Reflection.Module
An object derived from the Module class that describes a portable executable file.
Type: System.Type
The type, or a base type, of the custom attribute to search for.
Type: System.Boolean
This parameter is ignored, and does not affect the operation of this method.

Return Value

Type: System.Attribute()
An Attribute array that contains the custom attributes of type attributeType applied to element, or an empty array if no such custom attributes exist.


element or attributeType is Nothing.


attributeType is not derived from Attribute.

The return value contains the custom attributes for ancestors of element if inherit is true.

The following code example demonstrates the use of GetCustomAttributes, taking a Module as a parameter.

Imports System
Imports System.Reflection
Imports System.ComponentModel

' Give the Module some attributes.
<Module: Description("A sample description")> 

' Make the CLSCompliant attribute False.
' The CLSCompliant attribute is applicable for /target:module.
<Module: CLSCompliant(False)> 

Module DemoModule

    Sub Main()
        ' Get the Module type to access its metadata.
        Dim modType As Reflection.Module = GetType(DemoModule).Module
        Dim attr As Attribute
        ' Iterate through all the attributes for the module.
        For Each attr In Attribute.GetCustomAttributes(modType)
            ' Check for the Description attribute.
            If TypeOf attr Is DescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim descAttr As DescriptionAttribute = _
                    CType(attr, DescriptionAttribute)
                Console.WriteLine("Module {0} has the description ""{1}"".", _
                    modType.Name, descAttr.Description)

            ' Check for the CLSCompliant attribute.
            ElseIf TypeOf attr Is CLSCompliantAttribute Then
                ' Convert the attribute to access its data.
                Dim CLSCompAttr As CLSCompliantAttribute = _
                    CType(attr, CLSCompliantAttribute)
                Dim strCompliant As String
                If CLSCompAttr.IsCompliant Then
                    strCompliant = "is"
                    strCompliant = "is not"
                End If
                Console.WriteLine("Module {0} {1} CLSCompliant.", _
                    modType.Name, strCompliant)
            End If
    End Sub
End Module

' Output:
' Module CustAttrs2VB.exe has the description "A sample description".
' Module CustAttrs2VB.exe is not CLSCompliant.

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

© 2015 Microsoft