Imports System
Imports System.Reflection
Public Class Example
Public Shared Sub Generic(Of T)(ByVal toDisplay As T)
Console.WriteLine(vbCrLf & "Here it is: {0}", toDisplay)
End Sub
End Class
Public Class Test
Public Shared Sub Main()
Dim ex As Type = GetType(Example)
Dim mi As MethodInfo = ex.GetMethod("Generic")
DisplayGenericMethodInfo(mi)
End Sub 'Main
Private Shared Sub DisplayGenericMethodInfo(ByVal mi As MethodInfo)
Console.WriteLine(mi.ToString())
Console.WriteLine(mi.IsGenericMethodDefinition)
Console.WriteLine(mi.IsGenericMethod)
Console.WriteLine(mi.ContainsGenericParameters)
If mi.IsGenericMethod Then
Dim typeArguments As Type() = mi.GetGenericArguments()
Console.WriteLine(typeArguments.Length)
For Each tParam As Type In typeArguments
If tParam.IsGenericParameter Then
Console.WriteLine(tParam)
Console.WriteLine(tParam.GenericParameterPosition)
Console.WriteLine(tParam.DeclaringMethod)
Else
Console.WriteLine(vbTab & vbTab & tParam.ToString())
End If
Next tParam
End If
End Sub
End Class