Assembly.GetType 메서드
정의
오버로드
GetType(String, Boolean, Boolean) |
대/소문자를 무시할지 여부와 형식이 없으면 예외를 throw할지를 선택적으로 지정하여 어셈블리 인스턴스에서 지정된 이름을 가진 Type 개체를 가져옵니다.Gets the Type object with the specified name in the assembly instance, with the options of ignoring the case, and of throwing an exception if the type is not found. |
GetType(String, Boolean) |
어셈블리 인스턴스에서 지정된 이름을 가진 Type 개체를 가져오고, 형식을 찾을 수 없는 경우 선택적으로 예외를 throw합니다.Gets the Type object with the specified name in the assembly instance and optionally throws an exception if the type is not found. |
GetType(String) |
어셈블리 인스턴스에서 지정된 이름을 가진 Type 개체를 가져옵니다.Gets the Type object with the specified name in the assembly instance. |
GetType() |
GetType(String, Boolean, Boolean)
대/소문자를 무시할지 여부와 형식이 없으면 예외를 throw할지를 선택적으로 지정하여 어셈블리 인스턴스에서 지정된 이름을 가진 Type 개체를 가져옵니다.Gets the Type object with the specified name in the assembly instance, with the options of ignoring the case, and of throwing an exception if the type is not found.
public:
virtual Type ^ GetType(System::String ^ name, bool throwOnError, bool ignoreCase);
public Type GetType (string name, bool throwOnError, bool ignoreCase);
override this.GetType : string * bool * bool -> Type
Public Function GetType (name As String, throwOnError As Boolean, ignoreCase As Boolean) As Type
매개 변수
- name
- String
형식의 전체 이름입니다.The full name of the type.
- throwOnError
- Boolean
형식을 찾을 수 없는 경우 예외를 throw하려면 true
이고, false
을 반환하려면 null
입니다.true
to throw an exception if the type is not found; false
to return null
.
- ignoreCase
- Boolean
형식 이름의 대/소문자를 무시하면 true
이고, 그러지 않으면 false
입니다.true
to ignore the case of the type name; otherwise, false
.
반환
지정된 클래스를 나타내는 개체입니다.An object that represents the specified class.
구현
예외
name
이 잘못되었습니다.name
is invalid.
또는-or-
name
의 길이가 1024자를 초과합니다.The length of name
exceeds 1024 characters.
name
가 null
인 경우name
is null
.
throwOnError
가 true
이고 형식을 찾을 수 없습니다.throwOnError
is true
, and the type cannot be found.
name
에 종속 어셈블리가 필요하지만 이 어셈블리를 찾을 수 없습니다.name
requires a dependent assembly that could not be found.
name
에 종속 어셈블리가 필요하며 이 어셈블리를 찾았지만 로드할 수 없습니다.name
requires a dependent assembly that was found but could not be loaded.
또는-or-
현재 어셈블리가 리플렉션 전용 컨텍스트에 로드되었으며 name
에 종속 어셈블리가 필요하지만 이 어셈블리가 미리 로드되지 않았습니다.The current assembly was loaded into the reflection-only context, and name
requires a dependent assembly that was not preloaded.
name
에 종속 어셈블리가 필요하지만 파일이 유효한 어셈블리가 아닙니다.name
requires a dependent assembly, but the file is not a valid assembly.
또는-or-
name
에 현재 로드된 버전보다 높은 런타임 버전용으로 컴파일된 종속 어셈블리가 필요합니다.name
requires a dependent assembly which was compiled for a version of the runtime later than the currently loaded version.
설명
이 메서드는 현재 어셈블리 인스턴스만 검색 합니다.This method only searches the current assembly instance. name
매개 변수는 네임 스페이스를 포함 하지만 어셈블리는 포함 하지 않습니다.The name
parameter includes the namespace but not the assembly. 형식에 대 한 다른 어셈블리를 검색 하려면 선택적으로 어셈블리 표시 이름을 형식 이름의 일부로 포함할 수 있는 Type.GetType(String) 메서드 오버 로드를 사용 합니다.To search other assemblies for a type, use the Type.GetType(String) method overload, which can optionally include an assembly display name as part of the type name.
참고
형식이 다른 어셈블리에 전달 된 경우에도이 메서드에서 반환 됩니다.If the type has been forwarded to another assembly, it is still returned by this method. 형식 전달에 대 한 자세한 내용은 공용 언어 런타임의 형식 전달을 참조 하세요.For information on type forwarding, see Type Forwarding in the Common Language Runtime.
throwOnError
매개 변수는 형식을 찾을 수 없을 때 발생 하는 작업에만 영향을 줍니다.The throwOnError
parameter only affects what happens when the type is not found. Throw 될 수 있는 다른 예외에는 영향을 주지 않습니다.It does not affect any other exceptions that might be thrown. 특히, 형식을 찾았지만 로드할 수 없는 경우 throwOnError
false
경우에도 TypeLoadException throw 될 수 있습니다.In particular, if the type is found but cannot be loaded, TypeLoadException can be thrown even if throwOnError
is false
.
GetType(String, Boolean)
어셈블리 인스턴스에서 지정된 이름을 가진 Type 개체를 가져오고, 형식을 찾을 수 없는 경우 선택적으로 예외를 throw합니다.Gets the Type object with the specified name in the assembly instance and optionally throws an exception if the type is not found.
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
형식의 전체 이름입니다.The full name of the type.
- throwOnError
- Boolean
형식을 찾을 수 없는 경우 예외를 throw하려면 true
이고, false
을 반환하려면 null
입니다.true
to throw an exception if the type is not found; false
to return null
.
반환
지정된 클래스를 나타내는 개체입니다.An object that represents the specified class.
구현
예외
name
이 잘못되었습니다.name
is invalid.
또는-or-
name
의 길이가 1024자를 초과합니다.The length of name
exceeds 1024 characters.
name
가 null
입니다.name
is null
.
throwOnError
가 true
이고 형식을 찾을 수 없습니다.throwOnError
is true
, and the type cannot be found.
name
에 종속 어셈블리가 필요하지만 이 어셈블리를 찾을 수 없습니다.name
requires a dependent assembly that could not be found.
name
에 종속 어셈블리가 필요하며 이 어셈블리를 찾았지만 로드할 수 없습니다.name
requires a dependent assembly that was found but could not be loaded.
또는-or-
현재 어셈블리가 리플렉션 전용 컨텍스트에 로드되었으며 name
에 종속 어셈블리가 필요하지만 이 어셈블리가 미리 로드되지 않았습니다.The current assembly was loaded into the reflection-only context, and name
requires a dependent assembly that was not preloaded.
name
에 종속 어셈블리가 필요하지만 파일이 유효한 어셈블리가 아닙니다.name
requires a dependent assembly, but the file is not a valid assembly.
또는-or-
name
에 현재 로드된 버전보다 높은 런타임 버전용으로 컴파일된 종속 어셈블리가 필요합니다.name
requires a dependent assembly which was compiled for a version of the runtime later than the currently loaded version.
설명
이 메서드는 현재 어셈블리 인스턴스만 검색 합니다.This method only searches the current assembly instance. name
매개 변수는 네임 스페이스를 포함 하지만 어셈블리는 포함 하지 않습니다.The name
parameter includes the namespace but not the assembly. 형식에 대 한 다른 어셈블리를 검색 하려면 선택적으로 어셈블리 표시 이름을 형식 이름의 일부로 포함할 수 있는 Type.GetType(String) 메서드 오버 로드를 사용 합니다.To search other assemblies for a type, use the Type.GetType(String) method overload, which can optionally include an assembly display name as part of the type name.
참고
형식이 다른 어셈블리에 전달 된 경우에도이 메서드에서 반환 됩니다.If the type has been forwarded to another assembly, it is still returned by this method. 형식 전달에 대 한 자세한 내용은 공용 언어 런타임의 형식 전달을 참조 하세요.For information on type forwarding, see Type Forwarding in the Common Language Runtime.
throwOnError
매개 변수는 형식을 찾을 수 없을 때 발생 하는 작업에만 영향을 줍니다.The throwOnError
parameter only affects what happens when the type is not found. Throw 될 수 있는 다른 예외에는 영향을 주지 않습니다.It does not affect any other exceptions that might be thrown. 특히, 형식을 찾았지만 로드할 수 없는 경우 throwOnError
false
경우에도 TypeLoadException throw 될 수 있습니다.In particular, if the type is found but cannot be loaded, TypeLoadException can be thrown even if throwOnError
is false
.
GetType(String)
어셈블리 인스턴스에서 지정된 이름을 가진 Type 개체를 가져옵니다.Gets the Type object with the specified name in the assembly instance.
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
형식의 전체 이름입니다.The full name of the type.
반환
지정된 클래스를 나타내는 개체이며 클래스가 없는 경우 null
을 반환합니다.An object that represents the specified class, or null
if the class is not found.
구현
예외
name
이 잘못되었습니다.name
is invalid.
name
가 null
입니다.name
is null
.
name
에 종속 어셈블리가 필요하지만 이 어셈블리를 찾을 수 없습니다.name
requires a dependent assembly that could not be found.
Windows 스토어 앱용 .NET 또는 이식 가능한 클래스 라이브러리에서 대신 기본 클래스 예외 IOException을 catch합니다.In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, IOException, instead.
name
에 종속 어셈블리가 필요하며 이 어셈블리를 찾았지만 로드할 수 없습니다.
name
requires a dependent assembly that was found but could not be loaded.
또는-or-
현재 어셈블리가 리플렉션 전용 컨텍스트에 로드되었으며 name
에 종속 어셈블리가 필요하지만 이 어셈블리가 미리 로드되지 않았습니다.The current assembly was loaded into the reflection-only context, and name
requires a dependent assembly that was not preloaded.
name
에 종속 어셈블리가 필요하지만 파일이 유효한 어셈블리가 아닙니다.name
requires a dependent assembly, but the file is not a valid assembly.
또는-or-
name
에 현재 로드된 버전보다 높은 런타임 버전용으로 컴파일된 종속 어셈블리가 필요합니다.name
requires a dependent assembly which was compiled for a version of the runtime later than the currently loaded version.
예제
다음 예제에서는 Transportation
네임 스페이스에 추상 MeansOfTransportation
클래스를 정의 합니다.The following example defines an abstract MeansOfTransportation
class in the Transportation
namespace. GetType(String) 메서드를 호출 하 여 해당 Type 개체를 검색 하 고 Type.GetProperties 메서드를 호출 하 여 해당 형식의 속성을 나타내는 PropertyInfo 개체의 배열을 가져온 다음 형식의 추상 속성에 대 한 정보를 표시 합니다.It calls the GetType(String) method to retrieve its Type object, calls the Type.GetProperties method to get an array of PropertyInfo objects that represent the type's properties, and then displays information on the type's abstract properties. GetType(String) 메서드에 대 한 호출은 형식의 정규화 된 이름 (즉, 해당 형식 이름과 함께 네임 스페이스)을 사용 합니다.Note that the call to the GetType(String) method uses the type's fully qualified name (that is, its namespace along with its type name).
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)
설명
이 메서드는 현재 어셈블리 인스턴스만 검색 합니다.This method only searches the current assembly instance. name
매개 변수는 네임 스페이스를 포함 하지만 어셈블리는 포함 하지 않습니다.The name
parameter includes the namespace but not the assembly. 형식에 대 한 다른 어셈블리를 검색 하려면 선택적으로 어셈블리 표시 이름을 형식 이름의 일부로 포함할 수 있는 Type.GetType(String) 메서드 오버 로드를 사용 합니다.To search other assemblies for a type, use the Type.GetType(String) method overload, which can optionally include an assembly display name as part of the type name.
참고
형식이 다른 어셈블리에 전달 된 경우에도이 메서드에서 반환 됩니다.If the type has been forwarded to another assembly, it is still returned by this method. 형식 전달에 대 한 자세한 내용은 공용 언어 런타임의 형식 전달을 참조 하세요.For information on type forwarding, see Type Forwarding in the Common Language Runtime.