Represents type declarations: class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Dim instance As Type
Type is the root of the System.Reflection functionality and is the primary way to access metadata. Use the members of Type to get information about a type declaration, such as the constructors, methods, fields, properties, and events of a class, as well as the module and the assembly in which the class is deployed.
The C# typeof operator (GetType operator in Visual Basic, typeid operator in Visual C++) returns a Type object.
A Type object that represents a type is unique; that is, two Type object references refer to the same object if and only if they represent the same type. This allows for comparison of Type objects using reference equality.
This class is thread safe; multiple threads can concurrently read from an instance of this type. An instance of Type can represent any of the following types:
The following code example shows a few representative features of Type. The C# typeof operator (GetType operator in Visual Basic, typeid operator in Visual C++) is used to get a Type object representing String. From this Type object, the GetMethod method is used to get a MethodInfo representing the Substring overload that takes a starting location and a length.
To identify the overload signature, the code example creates a temporary array containing two Type objects representing int (Integer in Visual Basic).
Imports System
Imports System.Reflection Module Example Sub Main() Dim t As Type = GetType(String) Dim substr As MethodInfo = t.GetMethod("Substring", _
New Type() { GetType(Integer), GetType(Integer) }) Dim result As Object = _
substr.Invoke("Hello, World!", New Object() { 7, 5 })
Console.WriteLine("{0} returned ""{1}"".", substr, result) End Sub
End Module ' This code example produces the following output:
'
'System.String Substring(Int32, Int32) returned "World".
Previous: PropertyGrid 显示动态自定义属性 Next: TIOBE 编程语言排名指数的算法
Parent: 2008年12月
© 2008-2010 HubaPo.com 版权所有 Contact me