Assembly.GetAssembly(Type) Assembly.GetAssembly(Type) Assembly.GetAssembly(Type) Method

定義

指定した型が定義されている、現在読み込み済みのアセンブリを取得します。Gets the currently loaded assembly in which the specified type is defined.

public:
 static System::Reflection::Assembly ^ GetAssembly(Type ^ type);
public static System.Reflection.Assembly GetAssembly (Type type);
static member GetAssembly : Type -> System.Reflection.Assembly

パラメーター

type
Type Type Type

返されるアセンブリ内の型を表すオブジェクト。An object representing a type in the assembly that will be returned.

戻り値

指定された型が定義されているアセンブリ。The assembly in which the specified type is defined.

例外

次の例では、 Int32型を含むアセンブリを取得し、その名前とファイルの場所を表示します。The following example retrieves the assembly that contains the Int32 type and displays its name and file location.

using namespace System;
using namespace System::Reflection;

void main()
{
   // Get a Type object.
   Type^ t = int::typeid;
   // 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
using System;
using System.Reflection;

public class Example
{
   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
Imports System.Reflection

Module Example
   Public Sub Main()
      ' Get a Type object.
      Dim t As Type = GetType(Integer)
      ' Instantiate an Assembly class to the assembly housing the Integer type.
      Dim assem As Assembly = 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)
   End Sub
End Module
' 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プロパティの値を取得することと同じです。Calling this method is equivalent to retrieving the value of the Type.Assembly property. ただし、通常Type.Assembly 、このプロパティは優れたパフォーマンスを提供します。However, the Type.Assembly property typically offers superior performance.

このメソッドを呼び出すには、 Typeオブジェクトが必要です。これは、クラスが定義されているアセンブリが既に読み込まれている必要があることを意味します。In order to call this method, you must have a Type object, which means that the assembly in which the class is defined must already be loaded.

セキュリティ

ReflectionPermission
などの機構をInvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])使用して遅延バインディングが呼び出された場合。when invoked late-bound through mechanisms such as InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]). 関連付けられた列挙型:MemberAccessAssociated enumeration: MemberAccess

適用対象