Assembly.GetAssembly(Type) 메서드

정의

지정된 형식이 정의되어 있는 현재 로드된 어셈블리를 가져옵니다.

public:
 static System::Reflection::Assembly ^ GetAssembly(Type ^ type);
public static System.Reflection.Assembly? GetAssembly (Type type);
public static System.Reflection.Assembly GetAssembly (Type type);
static member GetAssembly : Type -> System.Reflection.Assembly
Public Shared Function GetAssembly (type As Type) As Assembly

매개 변수

type
Type

어셈블리에서 반환될 형식을 나타내는 개체입니다.

반환

Assembly

지정된 형식이 정의되어 있는 어셈블리입니다.

예외

type이(가) null인 경우

예제

다음 예제에서는 형식이 포함된 어셈블리를 Int32 검색하고 해당 이름과 파일 위치를 표시합니다.

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 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
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 검색하는 것과 같습니다. 그러나 이 속성은 Type.Assembly 일반적으로 뛰어난 성능을 제공합니다.

이 메서드를 호출하려면 개체가 있어야 합니다 Type . 즉, 클래스가 정의된 어셈블리가 이미 로드되어 있어야 합니다.

적용 대상