Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
<AttributeUsage(AttributeTargets.All)> Public Class MyAttribute
Inherits Attribute
Private myName As String
Public Sub New(ByVal name As String)
myName = name
End Sub 'New
Public ReadOnly Property Name() As String
Get
Return myName
End Get
End Property
End Class
Public Class MyClass1
<MyAttribute("This is an example attribute.")> Public Sub MyMethod(ByVal i As Integer)
Return
End Sub
End Class
Public Class MemberInfo_GetCustomAttributes
Public Shared Sub Main()
Dim myType As Type = GetType(MyClass1)
Dim myMembers As MemberInfo() = myType.GetMembers()
Dim i As Integer
For i = 0 To myMembers.Length - 1
Dim myAttributes As [Object]() = myMembers(i).GetCustomAttributes(False)
If myAttributes.Length > 0 Then
Console.WriteLine(myMembers(i))
Dim j As Integer
For j = 0 To myAttributes.Length - 1
Console.WriteLine(myAttributes(j))
Next j
End If
Next i
End Sub
End Class