Assembly.GetType 메서드

정의

Type 지정된 형식을 나타내는 개체를 가져옵니다.

오버로드

Name Description
GetType(String, Boolean, Boolean)

Type 대/소문자를 무시하고 형식을 찾을 수 없는 경우 예외를 throw하는 옵션을 사용하여 어셈블리 인스턴스에서 지정된 이름을 가진 개체를 가져옵니다.

GetType(String, Boolean)

Type 어셈블리 인스턴스에서 지정된 이름을 가진 개체를 가져오고 형식을 찾을 수 없는 경우 필요에 따라 예외를 throw합니다.

GetType()
GetType(String)

Type 어셈블리 인스턴스에서 지정된 이름을 가진 개체를 가져옵니다.

GetType(String, Boolean, Boolean)

Type 대/소문자를 무시하고 형식을 찾을 수 없는 경우 예외를 throw하는 옵션을 사용하여 어셈블리 인스턴스에서 지정된 이름을 가진 개체를 가져옵니다.

public:
 virtual Type ^ GetType(System::String ^ name, bool throwOnError, bool ignoreCase);
public virtual Type GetType(string name, bool throwOnError, bool ignoreCase);
public Type GetType(string name, bool throwOnError, bool ignoreCase);
override this.GetType : string * bool * bool -> Type
Public Overridable Function GetType (name As String, throwOnError As Boolean, ignoreCase As Boolean) As Type
Public Function GetType (name As String, throwOnError As Boolean, ignoreCase As Boolean) As Type

매개 변수

name
String

형식의 전체 이름입니다.

throwOnError
Boolean

true 형식을 찾을 수 없는 경우 예외를 throw하려면 입니다. false 를 반환 null합니다.

ignoreCase
Boolean

true형식 이름의 대/소문자를 무시하려면 입니다. 그렇지 않으면 . false

반품

지정된 클래스를 나타내는 개체입니다.

구현

예외

name 가 잘못되었습니다.

-또는-

길이 name 가 1024자를 초과합니다.

namenull입니다.

throwOnErrortrue고 형식을 찾을 수 없습니다.

name 에는 찾을 수 없는 종속 어셈블리가 필요합니다.

name 에는 검색되었지만 로드할 수 없는 종속 어셈블리가 필요합니다.

-또는-

현재 어셈블리가 리플렉션 전용 컨텍스트로 로드되었으며 name 미리 로드되지 않은 종속 어셈블리가 필요합니다.

name 에는 종속 어셈블리가 필요하지만 파일이 현재 로드된 런타임에 유효한 어셈블리가 아닙니다.

설명

이 메서드는 현재 어셈블리 인스턴스만 검색합니다. 매개 변수에는 name 네임스페이스가 포함되지만 어셈블리는 포함되지 않습니다. 다른 어셈블리에서 형식을 검색하려면 필요에 따라 어셈블리 표시 이름을 형식 이름의 일부로 포함할 수 있는 메서드 오버로드를 사용합니다 Type.GetType(String) .

.NET Core/.NET 5 이상에서 형식 이름 문자열에 어셈블리 정규화된 제네릭 형식 매개 변수가 있는 경우 해당 어셈블리 참조는 Assembly.GetType을 호출하는 메서드의 AssemblyLoadContext 또는 설정된 경우 AssemblyLoadContext.CurrentContextualReflectionContext 컨텍스트에 의해 로드됩니다.

메모

형식이 다른 어셈블리로 전달된 경우에도 이 메서드에서 반환됩니다. 형식 전달에 대한 자세한 내용은 공용 언어 런타임의 형식 전달을 참조하세요.

매개 변수는 throwOnError 형식을 찾을 수 없을 때 발생하는 동작에만 영향을 줍니다. throw될 수 있는 다른 예외에는 영향을 주지 않습니다. 특히 형식을 찾았지만 로드 TypeLoadException 할 수 없는 경우 있더라도 throwOnErrorfalsethrow할 수 있습니다.

적용 대상

GetType(String, Boolean)

Type 어셈블리 인스턴스에서 지정된 이름을 가진 개체를 가져오고 형식을 찾을 수 없는 경우 필요에 따라 예외를 throw합니다.

public:
 virtual Type ^ GetType(System::String ^ name, bool throwOnError);
public virtual Type GetType(string name, bool throwOnError);
override this.GetType : string * bool -> Type
Public Overridable Function GetType (name As String, throwOnError As Boolean) As Type

매개 변수

name
String

형식의 전체 이름입니다.

throwOnError
Boolean

true 형식을 찾을 수 없는 경우 예외를 throw하려면 입니다. false 를 반환 null합니다.

반품

지정된 클래스를 나타내는 개체입니다.

구현

예외

name 가 잘못되었습니다.

-또는-

길이 name 가 1024자를 초과합니다.

namenull입니다.

throwOnErrortrue고 형식을 찾을 수 없습니다.

name 에는 찾을 수 없는 종속 어셈블리가 필요합니다.

name 에는 검색되었지만 로드할 수 없는 종속 어셈블리가 필요합니다.

-또는-

현재 어셈블리가 리플렉션 전용 컨텍스트로 로드되었으며 name 미리 로드되지 않은 종속 어셈블리가 필요합니다.

name 에는 종속 어셈블리가 필요하지만 파일이 현재 로드된 런타임에 유효한 어셈블리가 아닙니다.

설명

이 메서드는 현재 어셈블리 인스턴스만 검색합니다. 매개 변수에는 name 네임스페이스가 포함되지만 어셈블리는 포함되지 않습니다. 다른 어셈블리에서 형식을 검색하려면 필요에 따라 어셈블리 표시 이름을 형식 이름의 일부로 포함할 수 있는 메서드 오버로드를 사용합니다 Type.GetType(String) .

.NET Core/.NET 5 이상에서 형식 이름 문자열에 어셈블리 정규화된 제네릭 형식 매개 변수가 있는 경우 해당 어셈블리 참조는 Assembly.GetType을 호출하는 메서드의 AssemblyLoadContext 또는 설정된 경우 AssemblyLoadContext.CurrentContextualReflectionContext 컨텍스트에 의해 로드됩니다.

메모

형식이 다른 어셈블리로 전달된 경우에도 이 메서드에서 반환됩니다. 형식 전달에 대한 자세한 내용은 공용 언어 런타임의 형식 전달을 참조하세요.

매개 변수는 throwOnError 형식을 찾을 수 없을 때 발생하는 동작에만 영향을 줍니다. throw될 수 있는 다른 예외에는 영향을 주지 않습니다. 특히 형식을 찾았지만 로드 TypeLoadException 할 수 없는 경우 있더라도 throwOnErrorfalsethrow할 수 있습니다.

적용 대상

GetType()

public:
 virtual Type ^ GetType();
public Type GetType();
override this.GetType : unit -> Type
Public Function GetType () As Type

반품

구현

적용 대상

GetType(String)

Type 어셈블리 인스턴스에서 지정된 이름을 가진 개체를 가져옵니다.

public:
 virtual Type ^ GetType(System::String ^ name);
public virtual Type GetType(string name);
override this.GetType : string -> Type
Public Overridable Function GetType (name As String) As Type

매개 변수

name
String

형식의 전체 이름입니다.

반품

지정된 클래스를 나타내는 개체이거나 null 클래스를 찾을 수 없는 경우

구현

예외

name 가 잘못되었습니다.

namenull입니다.

name 에는 찾을 수 없는 종속 어셈블리가 필요합니다.

name 에는 검색되었지만 로드할 수 없는 종속 어셈블리가 필요합니다.

-또는-

현재 어셈블리가 리플렉션 전용 컨텍스트로 로드되었으며 name 미리 로드되지 않은 종속 어셈블리가 필요합니다.

name 에는 종속 어셈블리가 필요하지만 파일이 현재 로드된 런타임에 유효한 어셈블리가 아닙니다.

예제

다음 예제에서는 네임스페이스에서 추상 MeansOfTransportation 클래스를 Transportation 정의합니다. 메서드를 GetType(String) 호출하여 해당 개체를 Type 검색하고, 메서드를 호출 Type.GetProperties 하여 형식의 속성을 나타내는 개체 배열 PropertyInfo 을 가져옵니다. 그런 다음 형식의 추상 속성에 대한 정보를 표시합니다. 메서드 호출 GetType(String) 은 형식의 정규화된 이름(즉, 해당 네임스페이스와 형식 이름)을 사용합니다.

using System;
using System.Reflection;

public class Example
{
    public static void Main()
    {
        Assembly assem = typeof(Example).Assembly;
        Type t = assem.GetType("Transportation.MeansOfTransportation");
        if (t != null)
        {
            Console.WriteLine($"Virtual properties in type {t.FullName}:");
            PropertyInfo[] props = t.GetProperties();
            int nVirtual = 0;
            for (int ctr = 0; ctr < props.Length; ctr++)
            {
                if (props[ctr].GetMethod.IsVirtual)
                {
                    Console.WriteLine($"   {props[ctr].Name} (type {props[ctr].PropertyType.FullName})");
                    nVirtual++;
                }
            }

            if (nVirtual == 0)
                Console.WriteLine("   No virtual properties");
        }
    }
}

namespace Transportation
{
    public abstract class MeansOfTransportation
    {
        abstract public bool HasWheels { get; set; }
        abstract public int Wheels { get; set; }
        abstract public bool ConsumesFuel { get; set; }
        abstract public bool Living { get; set; }
    }
}
// The example displays the following output:
//    Virtual properties in type Transportation.MeansOfTransportation:
//       HasWheels (type System.Boolean)
//       Wheels (type System.Int32)
//       ConsumesFuel (type System.Boolean)
//       Living (type System.Boolean)
Imports System.Reflection

Module Example
   Public Sub Main()
      Dim assem As Assembly = GetType(Example).Assembly
      Dim t As Type = assem.GetType("Transportation.MeansOfTransportation")
      If Not t Is Nothing Then
         Console.WriteLine("Virtual properties in type {0}:", 
                           t.FullName)
         Dim props() As PropertyInfo = t.GetProperties()
         Dim nVirtual As Integer = 0
         For ctr As Integer = 0 To props.Length - 1
            If props(ctr).GetMethod.IsVirtual Then
               Console.WriteLine("   {0} (type {1})",
                                 props(ctr).Name, 
                                 props(ctr).PropertyType.FullName)
               nVirtual += 1
            End If
         Next
         If nVirtual = 0 Then 
            Console.WriteLine("   No virtual properties")
         End If   
      End If   
   End Sub
End Module

Namespace Transportation
   Public MustInherit Class MeansOfTransportation
      Public MustOverride Property HasWheels As Boolean
      Public MustOverride Property Wheels As Integer
      Public MustOverride Property ConsumesFuel As Boolean
      Public MustOverride Property Living As Boolean
   End Class
End Namespace
' The example displays the following output:
'    Virtual properties in type Transportation.MeansOfTransportation:
'       HasWheels (type System.Boolean)
'       Wheels (type System.Int32)
'       ConsumesFuel (type System.Boolean)
'       Living (type System.Boolean)

설명

이 메서드는 현재 어셈블리 인스턴스만 검색합니다. 매개 변수에는 name 네임스페이스가 포함되지만 어셈블리는 포함되지 않습니다. 다른 어셈블리에서 형식을 검색하려면 필요에 따라 어셈블리 표시 이름을 형식 이름의 일부로 포함할 수 있는 메서드 오버로드를 사용합니다 Type.GetType(String) .

.NET Core/.NET 5 이상에서 형식 이름 문자열에 어셈블리 정규화된 제네릭 형식 매개 변수가 있는 경우 해당 어셈블리 참조는 Assembly.GetType을 호출하는 메서드의 AssemblyLoadContext 또는 설정된 경우 AssemblyLoadContext.CurrentContextualReflectionContext 컨텍스트에 의해 로드됩니다.

메모

형식이 다른 어셈블리로 전달된 경우에도 이 메서드에서 반환됩니다. 형식 전달에 대한 자세한 내용은 공용 언어 런타임의 형식 전달을 참조하세요.

적용 대상