Mega Code Archive
ParameterInfo GetCustomAttributes gets all the custom attributes defined on this parameter
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 MyClass1
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 myMethods As MethodInfo() = myType.GetMethods()
For i As Integer = 0 To myMethods.Length - 1
Dim myParameters As ParameterInfo() = myMethods(i).GetParameters()
If myParameters.Length > 0 Then
Console.WriteLine(myMethods(i))
For j As Integer = 0 To myParameters.Length - 1
Dim myAttributes As Object() = myParameters(j).GetCustomAttributes(GetType(MyAttribute), False)
If myAttributes.Length > 0 Then
Console.WriteLine(myParameters(j).Position)
Console.WriteLine(myParameters(j).Name)
Console.WriteLine(myParameters(j).ParameterType)
For k As Integer = 0 To myAttributes.Length - 1
Console.WriteLine("{0}", myAttributes(k))
Next k
End If
Next j
End If
Next i
End Sub
End Class