Typeクラスなどで使われる型名の多くはコード上での表記と変わりませんが、ジェネリック型では異なる表記が使われます。 例えばコード上ではList<T>
/List(Of T)
と記述される型にはSystem.Collections.Generic.List`1
といった表記が使われます。
型名では山括弧< >
で型引数名を記述する代わりに、バッククオート`
の後ろに型引数の数が記述されます。 例えばDictionary<TKey, TValue>
では型引数の数が2つとなるため、System.Collections.Generic.Dictionary`2
という表記になります。
ジェネリック型における型名の表記
Imports System
Imports System.Reflection
Class Sample
Shared Sub Main()
Console.WriteLine(GetType(System.Collections.Generic.List(Of )))
Console.WriteLine(GetType(System.Collections.Generic.List(Of Integer)))
Console.WriteLine(GetType(System.Collections.Generic.Dictionary(Of ,)))
Console.WriteLine(GetType(System.Action))
Console.WriteLine(GetType(System.Action(Of )))
Console.WriteLine(GetType(System.Action(Of ,)))
Console.WriteLine(GetType(System.Action(Of ,,)))
End Sub
End Class
実行結果
System.Collections.Generic.List`1[T] System.Collections.Generic.List`1[System.Int32] System.Collections.Generic.Dictionary`2[TKey,TValue] System.Action System.Action`1[T] System.Action`2[T1,T2] System.Action`3[T1,T2,T3]
リフレクションにおいてジェネリック型の名前を文字列で指定する場合には、この表記を使用する必要があります。