Assembly.GetTypes メソッド
このアセンブリで定義されている型を取得します。
Public Overridable Function GetTypes() As Type()
[C#]
public virtual Type[] GetTypes();
[C++]
public: virtual Type* GetTypes() [];
[JScript]
public function GetTypes() : Type[];
戻り値
このアセンブリで定義されているすべての型のオブジェクトを格納している Type 型の配列。
使用例
指定したアセンブリ内の型を表示する例を次に示します。
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
Dim Param As ParameterInfo
For Each 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()))
Next Param
[C#]
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());
}
[C++]
Assembly* SampleAssembly;
SampleAssembly = Assembly::LoadFrom(S"c:\\Sample.Assembly.dll");
// Obtain a reference to a method known to exist in assembly.
MethodInfo* Method = SampleAssembly->GetTypes()[0]->GetMethod(S"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
IEnumerator* myEnum = Params->GetEnumerator();
while (myEnum->MoveNext()) {
ParameterInfo* Param = __try_cast<ParameterInfo*>(myEnum->Current);
Console::WriteLine(S"Param= {0}", Param->Name);
Console::WriteLine(S" Type= {0}", Param->ParameterType);
Console::WriteLine(S" Position= {0}", __box(Param->Position));
Console::WriteLine(S" Optional= {0}", __box(Param->IsOptional));
}
[JScript]
var SampleAssembly : Assembly;
SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");
// Obtain a reference to a method known to exist in assembly.
var Method : MethodInfo = SampleAssembly.GetTypes()[0].GetMethod("Method1");
// Obtain a reference to the parameters collection of the MethodInfo instance.
var Params : ParameterInfo[] = Method.GetParameters();
// Display information about method parameters.
// Param = sParam1
// Type = System.String
// Position = 0
// Optional=False
for (var i : int in Params){
var Param : ParameterInfo = Params[i];
Console.WriteLine("Param=" + Param.Name.ToString());
Console.WriteLine(" Type=" + Param.ParameterType.ToString());
Console.WriteLine(" Position=" + Param.Position.ToString());
Console.WriteLine(" Optional=" + Param.IsOptional.ToString());
}
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
.NET Framework セキュリティ:
- ReflectionPermission (Type.InvokeMember などの機構を通じて遅延バインディングで呼び出すときに必要なアクセス許可) ReflectionPermissionFlag.MemberAccess (関連する列挙体)
- ReflectionPermission (非パブリック メソッドをリフレクションするために必要なアクセス許可) ReflectionPermissionFlag.MemberAccess 、 ReflectionPermissionFlag.TypeInformation (関連する列挙体)