rksoftware

Visual Studio とか C# とかが好きです

C# で現在読み込まれている Class を取得する

C# で現在読み込まれている Class を取得したいことが良くあります。

■ 前提知識

以前に書いた次の「C# で現在読み込まれている Assembly を取得する」記事が前提です。

■ コード

解説するよりコードが速いでしょう。
Console アプリを作成して Class の Type と定義されている Assembly を表示するコードです。

(Assembly クラスのインスタンス).GetTypes()

取得コード(例)

foreach (var type in AppDomain.CurrentDomain.GetAssemblies().SelectMany(asm => asm.GetTypes().Select(t => new { asm, t })))
    Console.WriteLine($"{type.asm.FullName}:{type.t.FullName}");

実行結果例は、大変なことになるので省略です。