Module.GetType 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 형식을 반환합니다.
오버로드
| Name | Description |
|---|---|
| GetType(String) |
대/소문자를 구분하는 검색을 수행하여 지정된 형식을 반환합니다. |
| GetType(String, Boolean) |
지정된 대/소문자를 구분하여 모듈을 검색하여 지정된 형식을 반환합니다. |
| GetType(String, Boolean, Boolean) |
지정된 형식을 반환하여 모듈을 대/소문자를 구분하여 검색할지 여부와 형식을 찾을 수 없는 경우 예외를 throw할지 여부를 지정합니다. |
GetType(String)
대/소문자를 구분하는 검색을 수행하여 지정된 형식을 반환합니다.
public:
virtual Type ^ GetType(System::String ^ className);
public virtual Type GetType(string className);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType(string className);
override this.GetType : string -> Type
[<System.Runtime.InteropServices.ComVisible(true)>]
override this.GetType : string -> Type
Public Overridable Function GetType (className As String) As Type
매개 변수
- className
- String
찾을 형식의 이름입니다. 네임스페이스를 사용하여 이름을 정규화해야 합니다.
반품
Type 형식이 이 모듈에 있으면 지정된 형식을 나타내는 개체이고, null그렇지 않으면 .
- 특성
예외
className은 null입니다.
클래스 이니셜라이저가 호출되고 예외가 throw됩니다.
className 는 길이가 0인 문자열입니다.
className 에는 찾을 수 없는 종속 어셈블리가 필요합니다.
className 에는 검색되었지만 로드할 수 없는 종속 어셈블리가 필요합니다.
-또는-
현재 어셈블리가 리플렉션 전용 컨텍스트로 로드되었으며 className 미리 로드되지 않은 종속 어셈블리가 필요합니다.
className 에는 종속 어셈블리가 필요하지만 파일은 유효한 어셈블리가 아닙니다.
-또는-
className 에는 현재 로드된 버전보다 나중에 런타임 버전에 대해 컴파일된 종속 어셈블리가 필요합니다.
예제
다음 예제에서는 지정된 모듈에 있는 형식의 이름을 표시합니다.
using System;
using System.Reflection;
namespace ReflectionModule_Examples
{
class MyMainClass
{
static void Main()
{
Module[] moduleArray;
moduleArray = typeof(MyMainClass).Assembly.GetModules(false);
//In a simple project with only one module, the module at index
// 0 will be the module containing these classes.
Module myModule = moduleArray[0];
Type myType;
myType = myModule.GetType("ReflectionModule_Examples.MyMainClass");
Console.WriteLine("Got type: {0}", myType.ToString());
}
}
}
Imports System.Reflection
'This code assumes that the root namespace is set to empty("").
Namespace ReflectionModule_Examples
Class MyMainClass
Shared Sub Main()
Dim moduleArray() As [Module]
moduleArray = GetType(MyMainClass).Assembly.GetModules(False)
'In a simple project with only one module, the module at index
' 0 will be the module containing these classes.
Dim myModule As [Module] = moduleArray(0)
Dim myType As Type
myType = myModule.GetType("ReflectionModule_Examples.MyMainClass")
Console.WriteLine("Got type: {0}", myType.ToString())
End Sub
End Class
End Namespace 'ReflectionModule_Examples
설명
메모
형식이 다른 어셈블리로 전달된 경우에도 이 메서드에서 반환됩니다. 형식 전달에 대한 자세한 내용은 공용 언어 런타임의 형식 전달을 참조하세요.
를 사용하여 Module.GetType특정 모듈에서 형식을 검색할 수 있습니다. 매니페스트가 포함된 모듈을 호출 Module.GetType 하면 전체 어셈블리가 검색되지 않습니다. 어셈블리에 있는 모듈에 관계없이 어셈블리에서 형식을 검색하려면 호출 Assembly.GetType해야 합니다.
적용 대상
GetType(String, Boolean)
지정된 대/소문자를 구분하여 모듈을 검색하여 지정된 형식을 반환합니다.
public:
virtual Type ^ GetType(System::String ^ className, bool ignoreCase);
public virtual Type GetType(string className, bool ignoreCase);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType(string className, bool ignoreCase);
override this.GetType : string * bool -> Type
[<System.Runtime.InteropServices.ComVisible(true)>]
override this.GetType : string * bool -> Type
Public Overridable Function GetType (className As String, ignoreCase As Boolean) As Type
매개 변수
- className
- String
찾을 형식의 이름입니다. 네임스페이스를 사용하여 이름을 정규화해야 합니다.
- ignoreCase
- Boolean
true대/소문자를 구분하지 않는 검색의 경우 그렇지 않으면 . false
반품
Type 형식이 이 모듈에 있으면 지정된 형식을 나타내는 개체이고, null그렇지 않으면 .
- 특성
예외
className은 null입니다.
클래스 이니셜라이저가 호출되고 예외가 throw됩니다.
className 는 길이가 0인 문자열입니다.
className 에는 찾을 수 없는 종속 어셈블리가 필요합니다.
className 에는 검색되었지만 로드할 수 없는 종속 어셈블리가 필요합니다.
-또는-
현재 어셈블리가 리플렉션 전용 컨텍스트로 로드되었으며 className 미리 로드되지 않은 종속 어셈블리가 필요합니다.
className 에는 종속 어셈블리가 필요하지만 파일은 유효한 어셈블리가 아닙니다.
-또는-
className 에는 현재 로드된 버전보다 나중에 런타임 버전에 대해 컴파일된 종속 어셈블리가 필요합니다.
예제
다음 예제에서는 지정된 모듈에 있는 형식의 이름을 표시하여 매개 변수를 ignoreCase 지정하여 false 대/소문자를 무시하지 않도록 합니다.
using System;
using System.Reflection;
namespace ReflectionModule_Examples
{
class MyMainClass
{
static void Main()
{
Module[] moduleArray;
moduleArray = typeof(MyMainClass).Assembly.GetModules(false);
//In a simple project with only one module, the module at index
// 0 will be the module containing these classes.
Module myModule = moduleArray[0];
Type myType;
myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", false);
Console.WriteLine("Got type: {0}", myType.ToString());
}
}
}
Imports System.Reflection
'This code assumes that the root namespace is set to empty("").
Namespace ReflectionModule_Examples
Class MyMainClass
Shared Sub Main()
Dim moduleArray() As [Module]
moduleArray = GetType(MyMainClass).Assembly.GetModules(False)
'In a simple project with only one module, the module at index
' 0 will be the module containing these classes.
Dim myModule As [Module] = moduleArray(0)
Dim myType As Type
myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", False)
Console.WriteLine("Got type: {0}", myType.ToString())
End Sub
End Class
End Namespace 'ReflectionModule_Examples
설명
메모
형식이 다른 어셈블리로 전달된 경우에도 이 메서드에서 반환됩니다. 형식 전달에 대한 자세한 내용은 공용 언어 런타임의 형식 전달을 참조하세요.
를 사용하여 Module.GetType특정 모듈에서 형식을 검색할 수 있습니다. 매니페스트가 포함된 모듈을 호출 Module.GetType 하면 전체 어셈블리가 검색되지 않습니다. 어셈블리에 있는 모듈에 관계없이 어셈블리에서 형식을 검색하려면 호출 Assembly.GetType해야 합니다.
적용 대상
GetType(String, Boolean, Boolean)
지정된 형식을 반환하여 모듈을 대/소문자를 구분하여 검색할지 여부와 형식을 찾을 수 없는 경우 예외를 throw할지 여부를 지정합니다.
public:
virtual Type ^ GetType(System::String ^ className, bool throwOnError, bool ignoreCase);
public virtual Type GetType(string className, bool throwOnError, bool ignoreCase);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType(string className, bool throwOnError, bool ignoreCase);
override this.GetType : string * bool * bool -> Type
[<System.Runtime.InteropServices.ComVisible(true)>]
override this.GetType : string * bool * bool -> Type
Public Overridable Function GetType (className As String, throwOnError As Boolean, ignoreCase As Boolean) As Type
매개 변수
- className
- String
찾을 형식의 이름입니다. 네임스페이스를 사용하여 이름을 정규화해야 합니다.
- throwOnError
- Boolean
true 형식을 찾을 수 없는 경우 예외를 throw하려면 입니다. false 를 반환 null합니다.
- ignoreCase
- Boolean
true대/소문자를 구분하지 않는 검색의 경우 그렇지 않으면 . false
반품
Type 이 모듈에서 형식이 선언된 경우 지정된 형식을 나타내는 개체이고, null그렇지 않으면 .
- 특성
예외
className은 null입니다.
클래스 이니셜라이저가 호출되고 예외가 throw됩니다.
className 는 길이가 0인 문자열입니다.
throwOnError 이 true고 형식을 찾을 수 없습니다.
className 에는 찾을 수 없는 종속 어셈블리가 필요합니다.
className 에는 검색되었지만 로드할 수 없는 종속 어셈블리가 필요합니다.
-또는-
현재 어셈블리가 리플렉션 전용 컨텍스트로 로드되었으며 className 미리 로드되지 않은 종속 어셈블리가 필요합니다.
className 에는 종속 어셈블리가 필요하지만 파일은 유효한 어셈블리가 아닙니다.
-또는-
className 에는 현재 로드된 버전보다 나중에 런타임 버전에 대해 컴파일된 종속 어셈블리가 필요합니다.
예제
다음 예제에서는 지정된 모듈에 있는 형식의 이름을 표시합니다. 및 ignoreCase 매개 변수는 throwOnError .로 false지정됩니다.
using System;
using System.Reflection;
namespace ReflectionModule_Examples
{
class MyMainClass
{
static void Main()
{
Module[] moduleArray;
moduleArray = typeof(MyMainClass).Assembly.GetModules(false);
//In a simple project with only one module, the module at index
// 0 will be the module containing this class.
Module myModule = moduleArray[0];
Type myType;
myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", false, false);
Console.WriteLine("Got type: {0}", myType.ToString());
}
}
}
Imports System.Reflection
'This code assumes that the root namespace is set to empty("").
Namespace ReflectionModule_Examples
Class MyMainClass
Shared Sub Main()
Dim moduleArray() As [Module]
moduleArray = GetType(MyMainClass).Assembly.GetModules(False)
'In a simple project with only one module, the module at index
' 0 will be the module containing this class.
Dim myModule As [Module] = moduleArray(0)
Dim myType As Type
myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", False, False)
Console.WriteLine("Got type: {0}", myType.ToString())
End Sub
End Class
End Namespace 'ReflectionModule_Examples
설명
매개 변수는 throwOnError 형식을 찾을 수 없을 때 발생하는 동작에만 영향을 줍니다. throw될 수 있는 다른 예외에는 영향을 주지 않습니다. 특히 형식을 찾았지만 로드 TypeLoadException 할 수 없는 경우 있더라도 throwOnErrorfalsethrow할 수 있습니다.
메모
형식이 다른 어셈블리로 전달된 경우에도 이 메서드에서 반환됩니다. 형식 전달에 대한 자세한 내용은 공용 언어 런타임의 형식 전달을 참조하세요.
를 사용하여 Module.GetType특정 모듈에서 형식을 검색할 수 있습니다. 매니페스트가 포함된 모듈을 호출 Module.GetType 하면 전체 어셈블리가 검색되지 않습니다. 어셈블리에 있는 모듈에 관계없이 어셈블리에서 형식을 검색하려면 호출 Assembly.GetType해야 합니다.