System.Type.GetInterface Method

Searches for the interface with the specified name.

Syntax

public Type GetInterface (string name)

Parameters

name
The string containing the name of the interface to get. For generic interfaces, this is the mangled name.

Returns

An object representing the interface with the specified name, implemented or inherited by the current Type, if found; otherwise, null.

Exceptions

TypeReason
ArgumentNullException name is null.
System.Reflection.AmbiguousMatchExceptionThe current instance represents a type that implements the same generic interface with different type arguments.

Remarks

The search for name is case-sensitive.

If the current Type represents a constructed generic type, this method returns the Type with the type parameters replaced by the appropriate type arguments.

If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the interface constraints and any interfaces inherited from class or interface constraints.

Note:

For generic interfaces, the name parameter is the mangled name, ending with a grave accent (`) and the number of type parameters. This is true for both generic interface definitions and constructed generic interfaces. For example, to find IExample<T> (IExample(Of T) in Visual Basic) or IExample<string> (IExample(Of String) in Visual Basic), search for "IExample`1".

Requirements

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