Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
_
Public Class MyAttribute
Inherits Attribute
Private myName As String
Public Sub New(ByVal name As String)
myName = name
End Sub
Public ReadOnly Property Name() As String
Get
Return myName
End Get
End Property
End Class
_
Public Class MyDerivedAttribute
Inherits MyAttribute
Public Sub New(ByVal name As String)
MyBase.New(name)
End Sub
End Class
Public Class MyClass1
Public Sub MyMethod( _
ByVal i As Integer, _
_
ByVal j As Integer, _
ByVal k As Integer)
Return
End Sub
End Class
Public Class MemberInfo_GetCustomAttributes
Public Shared Sub Main()
Dim myType As Type = GetType(MyClass1)
Dim myMethods As MethodInfo() = myType.GetMethods()
For Each mi As MethodInfo In myMethods
Dim myParameters As ParameterInfo() = mi.GetParameters()
If myParameters.Length > 0 Then
For Each pi As ParameterInfo In myParameters
If pi.IsDefined(GetType(MyAttribute), False) Then
Console.WriteLine(pi.Position)
Console.WriteLine(pi.Name)
Console.WriteLine(pi.ParameterType)
End If
Next
End If
Next
End Sub
End Class