다음을 통해 공유


Assembly.GetTypes 메서드

정의

이 어셈블리에 정의된 모든 형식을 가져옵니다.

public:
 virtual cli::array <Type ^> ^ GetTypes();
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")]
public virtual Type[] GetTypes();
public virtual Type[] GetTypes();
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")>]
abstract member GetTypes : unit -> Type[]
override this.GetTypes : unit -> Type[]
abstract member GetTypes : unit -> Type[]
override this.GetTypes : unit -> Type[]
Public Overridable Function GetTypes () As Type()

반환

Type[]

이 어셈블리에 정의된 모든 형식을 포함하는 배열입니다.

구현

특성

예외

어셈블리에는 로드할 수 없는 하나 이상의 형식이 포함되어 있습니다. 이 예외의 속성에서 반환된 Types 배열에는 로드된 각 형식 및 null 로드할 수 없는 각 형식에 대한 개체가 포함 Type 되며LoaderExceptions, 속성에는 로드할 수 없는 각 형식에 대한 예외가 포함됩니다.

예제

다음 예제에서는 지정된 어셈블리의 형식에 한 메서드의 매개 변수를 표시합니다.

Assembly SampleAssembly;
SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");
// Obtain a reference to a method known to exist in assembly.
MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod("Method1");
// Obtain a reference to the parameters collection of the MethodInfo instance.
ParameterInfo[] Params = Method.GetParameters();
// Display information about method parameters.
// Param = sParam1
//   Type = System.String
//   Position = 0
//   Optional=False
foreach (ParameterInfo Param in Params)
{
    Console.WriteLine("Param=" + Param.Name.ToString());
    Console.WriteLine("  Type=" + Param.ParameterType.ToString());
    Console.WriteLine("  Position=" + Param.Position.ToString());
    Console.WriteLine("  Optional=" + Param.IsOptional.ToString());
}
Dim SampleAssembly As [Assembly]
SampleAssembly = [Assembly].LoadFrom("c:\Sample.Assembly.dll")
' Obtain a reference to a method known to exist in assembly.
Dim Method As MethodInfo = SampleAssembly.GetTypes()(0).GetMethod("Method1")
' Obtain a reference to the parameters collection of the MethodInfo instance.
Dim Params As ParameterInfo() = Method.GetParameters()
' Display information about method parameters.
' Param = sParam1
'   Type = System.String
'   Position = 0
'   Optional=False
For Each Param As ParameterInfo In Params
    Console.WriteLine(("Param=" + Param.Name.ToString()))
    Console.WriteLine(("  Type=" + Param.ParameterType.ToString()))
    Console.WriteLine(("  Position=" + Param.Position.ToString()))
    Console.WriteLine(("  Optional=" + Param.IsOptional.ToString()))
Next

설명

반환된 배열에는 중첩된 형식과 비공용 형식이 포함됩니다. public 형식만 검색하려면 메서드를 GetExportedTypes 사용합니다.

메서드가 GetTypes 어셈블리에서 호출되고 해당 어셈블리의 형식이 로드되지 않은 어셈블리의 형식에 종속된 경우(예: 두 번째 어셈블리의 형식에서 파생되는 경우) ReflectionTypeLoadException throw됩니다. 예를 들어 첫 번째 어셈블리가 또는 ReflectionOnlyLoadFrom 메서드를 사용하여 ReflectionOnlyLoad 로드되고 두 번째 어셈블리가 로드되지 않은 경우 이 문제가 발생할 수 있습니다. 메서드를 호출할 때 두 번째 어셈블리를 배치할 수 없는 경우 및 LoadFile 메서드를 사용하여 Load 로드된 어셈블리에서도 GetTypes 발생할 수 있습니다.

메모

형식이 다른 어셈블리로 전달된 경우 반환된 배열에 포함되지 않습니다. 형식 전달에 대한 자세한 내용은 공용 언어 런타임의 형식 전달을 참조하세요.

개체 배열 Type 대신 개체 컬렉션을 검색 TypeInfo 하려면 이 속성을 사용합니다Assembly.DefinedTypes.

적용 대상