英語で読む

次の方法で共有


Assembly.GetAssembly(Type) メソッド

定義

指定した型が定義されている、現在読み込み済みのアセンブリを取得します。

C#
public static System.Reflection.Assembly? GetAssembly (Type type);
C#
public static System.Reflection.Assembly GetAssembly (Type type);

パラメーター

type
Type

返されるアセンブリ内の型を表すオブジェクト。

戻り値

指定された型が定義されているアセンブリ。

例外

typenullです。

次の例では、型を含むアセンブリを Int32 取得し、その名前とファイルの場所を表示します。

C#
using System;
using System.Reflection;

public class Example2
{
    public static void Main()
    {
        // Get a Type object.
        Type t = typeof(int);
        // Instantiate an Assembly class to the assembly housing the Integer type.
        Assembly assem = Assembly.GetAssembly(t);
        // Display the name of the assembly.
        Console.WriteLine("Name: {0}", assem.FullName);
        // Get the location of the assembly using the file: protocol.
        Console.WriteLine("CodeBase: {0}", assem.CodeBase);
    }
}
// The example displays output like the following:
//    Name: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
//    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll

注釈

このメソッドの呼び出しは、 プロパティの Type.Assembly 値を取得することと同じです。 ただし、通常、 プロパティは Type.Assembly 優れたパフォーマンスを提供します。

このメソッドを呼び出すには、 オブジェクトが Type 必要です。つまり、クラスが定義されているアセンブリが既に読み込まれている必要があります。

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1