Assembly.GetTypes 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이 어셈블리에 정의된 모든 형식을 가져옵니다.
public:
virtual cli::array <Type ^> ^ GetTypes();
public virtual Type[] GetTypes ();
abstract member GetTypes : unit -> Type[]
override this.GetTypes : unit -> Type[]
Public Overridable Function GetTypes () As Type()
반환
이 어셈블리에 정의되어 있는 모든 형식이 포함된 배열입니다.
구현
예외
어셈블리에 로드할 수 없는 하나 이상의 형식이 포함되어 있습니다.
Types 속성에는 로드할 수 없는 각 형식에 대한 예외가 포함되어 있으나, 이 예외의 Type 속성에 의해 반환된 배열에는 로드된 각 형식에 대한 null 개체 및 로드할 수 없는 각 형식에 대한 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.
array<ParameterInfo^>^ Params = Method->GetParameters();
// Display information about method parameters.
// Param = sParam1
// Type = System::String
// Position = 0
// Optional=False
for each ( ParameterInfo^ Param in Params )
{
Console::WriteLine( "Param= {0}", Param->Name );
Console::WriteLine( " Type= {0}", Param->ParameterType );
Console::WriteLine( " Position= {0}", Param->Position );
Console::WriteLine( " Optional= {0}", Param->IsOptional );
}
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
설명
반환된 배열에는 중첩 및 비공용 형식이 포함됩니다. 공용 형식만 검색하려면 메서드를 GetExportedTypes 사용합니다.
메서드가 GetTypes 어셈블리에서 호출되고 해당 어셈블리의 형식이 로드되지 않은 어셈블리의 형식에 종속된 경우(예: 두 번째 어셈블리의 형식에서 파생되는 경우) ReflectionTypeLoadException 이 throw됩니다. 예를 들어 첫 번째 어셈블리가 또는 ReflectionOnlyLoadFrom 메서드를 사용하여 ReflectionOnlyLoad 로드되고 두 번째 어셈블리가 로드되지 않은 경우 이 문제가 발생할 수 있습니다. 메서드가 호출될 때 두 번째 어셈블리를 배치할 수 없는 경우 및 LoadFile 메서드를 사용하여 Load 로드된 어셈블리에서도 GetTypes 발생할 수 있습니다.
참고
형식이 다른 어셈블리로 전달된 경우 반환된 배열에 포함되지 않습니다. 형식 전달에 대한 자세한 내용은 공용 언어 런타임의 형식 전달을 참조하세요.
개체 배열 대신 Type 개체의 TypeInfo 컬렉션을 검색하려면 속성을 사용합니다Assembly.DefinedTypes.