I've created a MyFunc extension (in Module Extensions) for all the base types as well as generic arrays, ICollection(Of T) and Dictionary(Of String,T):
Function MyFunc(Of T)(a() As T) As String
Function MyFunc(Of T)(collection As ICollection(Of T)) As String
Function MyFunc(Of T)(dict As Dictionary(Of String,T)) As String
In most cases, I use the functions directly (i.e. "Test".MyFunc()) but there are late-bound situations for which I'm working on a generic function:
Function LateBoundMyFunc(val As Object) As String
Dim t As Type = val.GetType
If TypeOf val Is Array Then
t = ????
ElseIf TypeOf val Is ICollection
t = ????
ElseIf Typeof val Is Dictionary(Of String,) <- This fails
t = ????
End If
Return CType(GetType(Extensions).GetMethod("MyFunc",New Type(){t}).Invoke(Nothing,New Object(){val}),String)
It's fairly simple to handle the base types, but what do I put in place of the ???? and how do I test for Dictionary(Of String,T)?