Attribute.GetCustomAttributes Method (Module, Boolean)
.NET Framework (current version)
Retrieves an array of the custom attributes applied to a module. Parameters specify the module, and an ignored search option.
Assembly: mscorlib (in mscorlib.dll)
Public Shared Function GetCustomAttributes ( element As Module, inherit As Boolean ) As Attribute()
Parameters
- element
-
Type:
System.Reflection.Module
An object derived from the Module class that describes a portable executable file.
- inherit
-
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 applied to element, or an empty array if no such custom attributes exist.
| Exception | Condition |
|---|---|
| ArgumentNullException | element or attributeType is null. |
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" Else strCompliant = "is not" End If Console.WriteLine("Module {0} {1} CLSCompliant.", _ modType.Name, strCompliant) End If Next End Sub End Module ' Output: ' Module CustAttrs2VB.exe has the description "A sample description". ' Module CustAttrs2VB.exe is not CLSCompliant.
.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Show: