Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Assembly.GetTypes Method

Gets the types defined in this assembly.

[Visual Basic]
Public Overridable Function GetTypes() As Type()
[C#]
public virtual Type[] GetTypes();
[C++]
public: virtual Type* GetTypes() [];
[JScript]
public function GetTypes() : Type[];

Return Value

An array of type Type containing objects for all the types defined in this assembly.

Example

The following example displays the types in the specified assembly.

[Visual Basic] 
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());
}

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

.NET Framework Security: 

See Also

Assembly Class | Assembly Members | System.Reflection Namespace

Show:
© 2014 Microsoft