Assembly.GetType 메서드

정의

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

오버로드

GetType(String, Boolean, Boolean)

대/소문자를 무시할지 여부와 형식이 없으면 예외를 throw할지를 선택적으로 지정하여 어셈블리 인스턴스에서 지정된 이름을 가진 Type 개체를 가져옵니다.

GetType(String, Boolean)

어셈블리 인스턴스에서 지정된 이름을 가진 Type 개체를 가져오고, 형식을 찾을 수 없는 경우 선택적으로 예외를 throw합니다.

GetType(String)

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

GetType()

GetType(String, Boolean, Boolean)

Source:
Assembly.cs
Source:
Assembly.cs
Source:
Assembly.cs

대/소문자를 무시할지 여부와 형식이 없으면 예외를 throw할지를 선택적으로 지정하여 어셈블리 인스턴스에서 지정된 이름을 가진 Type 개체를 가져옵니다.

public:
 virtual Type ^ GetType(System::String ^ name, bool throwOnError, bool ignoreCase);
public virtual Type GetType (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

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

ignoreCase
Boolean

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

반환

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

구현

예외

name이 잘못되었습니다.

또는

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

name이(가) null인 경우

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

name 에 종속 어셈블리가 필요하지만 이 어셈블리를 찾을 수 없습니다.

name에 종속 어셈블리가 필요하며 이 어셈블리를 찾았지만 로드할 수 없습니다.

또는

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

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

설명

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

참고

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

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

적용 대상

GetType(String, Boolean)

Source:
Assembly.cs
Source:
Assembly.cs
Source:
Assembly.cs

어셈블리 인스턴스에서 지정된 이름을 가진 Type 개체를 가져오고, 형식을 찾을 수 없는 경우 선택적으로 예외를 throw합니다.

public:
 virtual Type ^ GetType(System::String ^ name, bool throwOnError);
public virtual Type? GetType (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

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

반환

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

구현

예외

name이 잘못되었습니다.

또는

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

name이(가) null인 경우

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

name 에 종속 어셈블리가 필요하지만 이 어셈블리를 찾을 수 없습니다.

name에 종속 어셈블리가 필요하며 이 어셈블리를 찾았지만 로드할 수 없습니다.

또는

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

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

설명

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

참고

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

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

적용 대상

GetType(String)

Source:
Assembly.cs
Source:
Assembly.cs
Source:
Assembly.cs

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

public:
 virtual Type ^ GetType(System::String ^ name);
public virtual Type GetType (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이 잘못되었습니다.

name이(가) null인 경우

name 에 종속 어셈블리가 필요하지만 이 어셈블리를 찾을 수 없습니다.

name에 종속 어셈블리가 필요하며 이 어셈블리를 찾았지만 로드할 수 없습니다.

또는

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

참고: Windows 스토어 앱 또는 이식 가능한 클래스 라이브러리용 .NET에서 기본 클래스 예외 를 IOException대신 catch합니다.

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

예제

다음 예제에서는 네임스페이스에서 추상 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)

설명

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

참고

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

적용 대상

GetType()

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

반환

구현

적용 대상