アセンブリに定義されている型のうち、別のアセンブリに転送された(forwarded)型を取得するには、Assembly.GetForwardedTypesメソッドを使うことができます。 このメソッドは、.NET Standard 2.1/.NET Core 2.1以降で使用できます。
このメソッドでは、属性TypeForwardedToAttribute/TypeForwardedFromAttributeによって転送された型が取得されます。 より具体的には、過去のバージョンではこのアセンブリで定義・実装されていたが、現在では他のアセンブリに実装が移された型が取得されます。
アセンブリから他アセンブリに転送された型情報を取得する .NET Standard 2.1/.NET Core 2.1
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Reflection
Class Sample
Shared Sub Main()
' System.Collections.dll(.NET Standard 1.6)をロードする
Dim name As New AssemblyName("System.Collections, Version=4.0.10.0, PublicKeyToken=b03f5f7f11d50a3a")
Dim assm As [Assembly] = [Assembly].Load(name)
Console.WriteLine($"{name.FullName} -> {assm.GetName().FullName}")
Console.WriteLine()
' アセンブリで公開される型・他アセンブリへ転送される型の一覧と、転送先のアセンブリを表示する
Dim forwardedTypes As New HashSet(Of Type)(assm.GetForwardedTypes())
Dim exportedTypes As New HashSet(Of Type)(assm.GetExportedTypes())
For Each t As Type In exportedTypes.Union(forwardedTypes)
Console.Write($"{t,-100}")
Console.Write(If(forwardedTypes.Contains(t), "-> ", " @ "))
Console.WriteLine(t.[Assembly].GetName().FullName)
Next
End Sub
End Class
実行結果
System.Collections, Version=4.0.10.0, PublicKeyToken=b03f5f7f11d50a3a -> System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.BitArray @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.StructuralComparisons @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.CollectionExtensions @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.LinkedList`1[T] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.LinkedList`1+Enumerator[T] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.LinkedListNode`1[T] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.Queue`1[T] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.Queue`1+Enumerator[T] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedDictionary`2[TKey,TValue] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedDictionary`2+Enumerator[TKey,TValue] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedDictionary`2+KeyCollection[TKey,TValue] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedDictionary`2+KeyCollection+Enumerator[TKey,TValue] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedDictionary`2+ValueCollection[TKey,TValue] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedDictionary`2+ValueCollection+Enumerator[TKey,TValue] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedDictionary`2+KeyValuePairComparer[TKey,TValue] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.TreeSet`1[T] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedList`2[TKey,TValue] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedList`2+KeyList[TKey,TValue] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedList`2+ValueList[TKey,TValue] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedSet`1[T] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.SortedSet`1+Enumerator[T] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.Stack`1[T] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.Stack`1+Enumerator[T] @ System.Collections, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Generic.Comparer`1[T] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.Dictionary`2[TKey,TValue] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.Dictionary`2+Enumerator[TKey,TValue] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.Dictionary`2+KeyCollection[TKey,TValue] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator[TKey,TValue] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.Dictionary`2+ValueCollection[TKey,TValue] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator[TKey,TValue] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.EqualityComparer`1[T] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.HashSet`1[T] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.HashSet`1+Enumerator[T] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.List`1[T] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.List`1+Enumerator[T] -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e System.Collections.Generic.ReferenceEqualityComparer -> System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e