アセンブリに定義されている型のうち、別のアセンブリに転送された(forwarded)型を取得するには、Assembly.GetForwardedTypesメソッドを使うことができます。 このメソッドは、.NET Standard 2.1/.NET Core 2.1以降で使用できます。
このメソッドでは、属性TypeForwardedToAttribute/TypeForwardedFromAttributeによって転送された型が取得されます。 より具体的には、過去のバージョンではこのアセンブリで定義・実装されていたが、現在では他のアセンブリに実装が移された型が取得されます。
アセンブリから他アセンブリに転送された型情報を取得する .NET Standard 2.1/.NET Core 2.1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
class Sample {
static void Main()
{
// System.Collections.dll(.NET Standard 1.6)をロードする
var name = new AssemblyName("System.Collections, Version=4.0.10.0, PublicKeyToken=b03f5f7f11d50a3a");
var assm = Assembly.Load(name);
Console.WriteLine($"{name.FullName} -> {assm.GetName().FullName}");
Console.WriteLine();
// アセンブリで公開される型・他アセンブリへ転送される型の一覧と、転送先のアセンブリを表示する
var forwardedTypes = new HashSet<Type>(assm.GetForwardedTypes());
var exportedTypes = new HashSet<Type>(assm.GetExportedTypes());
foreach (var t in exportedTypes.Union(forwardedTypes)) {
Console.Write($"{t,-100}");
Console.Write(forwardedTypes.Contains(t) ? "-> " : " @ ");
Console.WriteLine(t.Assembly.GetName().FullName);
}
}
}
実行結果
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