Mono Class Library: System.Type Overview | Members

System.Type.GetType Method

Returns the Type with the specified name, optionally performing a case-insensitive search and optionally throwing an exception if an error occurs while loading the Type.

public static Type GetType (string typeName, bool throwOnError, bool ignoreCase)

Parameters

typeName
A string containing the name of the Type to return.
throwOnError
A bool. Specify true to throw a TypeLoadException if an error occurs while loading the Type. Specify false to ignore errors while loading the Type.
ignoreCase
A bool. Specify true to perform a case-insensitive search for typeName. Specify false to perform a case-sensitive search for typeName .

Returns

The Type with the specified name, if found; otherwise, null. If the requested type is non-public and the caller does not have permission to reflect non-public objects outside the current assembly, this method returns null.

Permissions

TypeReason
System.Security.Permissions.ReflectionPermissionRequires permission to retrieve information on non-public members of types in loaded assemblies. See System.Security.Permissions.ReflectionPermissionFlag.TypeInformation.

Exceptions

TypeReason
ArgumentNullExceptiontypeName is null.
System.Reflection.TargetInvocationExceptionA type initializer was invoked and threw an exception.
TypeLoadExceptionthrowOnError is true and an error was encountered while loading the selected Type.

Remarks

typeName can be a simple type name, a fully qualified name, or a complex name that includes an assembly name.

Note: Type.AssemblyQualifiedName returns a fully qualified type name including nested types, the assembly name, and generic type arguments.

If typeName includes only the name of the Type, this method searches in the calling object's assembly, then in the mscorlib.dll assembly. If typeName is fully qualified with the partial or complete assembly name, this method searches in the specified assembly.

Note:

The following table shows calls to GetType for various types. (Some long strings have been wrapped to fit in the right column.)

To Get this TypeUse this String
An unmanaged pointer to MyTypeType.GetType("MyType*")
An unmanaged pointer to a pointer to MyTypeType.GetType("MyType**")
A managed pointer or reference to MyTypeType.GetType("MyType&")Note that unlike pointers, references are limited to one level.
A parent class and a nested classType.GetType("MyParentClass+MyNestedClass")
A one-dimensional array with a lower bound of 0Type.GetType("MyArray[]")
A one-dimensional array with an unknown lower boundType.GetType("MyArray[*]")
An n-dimensional arrayA comma (,) inside the brackets a total of n-1 times. For example, System.Object[,,] represents a three-dimensional Object array.
A two-dimensional array's arrayType.GetType("MyArray[][]")
A rectangular two-dimensional array with unknown lower boundsType.GetType("MyArray[*,*]") or Type.GetType("MyArray[,]")
A generic type with one type argumentType.GetType("MyGenericType[MyType]")
A generic type with two type argumentsType.GetType("MyGenericType[MyType,AnotherType]")
A generic type with two assembly-qualified type argumentsType.GetType("MyGenericType[[MyType,MyAssembly], [AnotherType,AnotherAssembly]]")
An assembly-qualified generic type with an assembly-qualified type argumentType.GetType("MyGenericType[[MyType,MyAssembly]] ,MyGenericTypeAssembly")
A generic type whose type argument is a generic type with two type argumentsType.GetType("MyGenericType[AnotherGenericType [MyType,AnotherType]]")

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0