Type.GetInterface Method (String, Boolean)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

When overridden in a derived class, searches for the specified interface, specifying whether to do a case-insensitive search for the interface name.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

Public MustOverride Function GetInterface (
	name As String,
	ignoreCase As Boolean
) As Type


Type: System.String

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

Type: System.Boolean

true to ignore the case of that part of name that specifies the simple interface name (the part that specifies the namespace must be correctly cased).


false to perform a case-sensitive search for all parts of name.

Return Value

Type: System.Type

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

Exception Condition

name is null.


The current Type represents a type that implements the same generic interface with different type arguments.

The ignoreCase parameter applies only to the simple interface name, not to the namespace. The portion of name that specifies the namespace must have the correct case, or the interface will not be found. For example, the string "System.icomparable" finds the IComparable interface, but the string "system.icomparable" does not.

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.


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".

The following code example uses the GetInterface(String, Boolean) method to perform a case-insensitive search of the Hashtable class for the IEnumerable interface.

The code example also demonstrates the GetInterface(String) method overload and the GetInterfaceMap method.

   Public Shared Sub Main()
      Dim hashtableObj As New Hashtable()
      Dim objType As Type = hashtableObj.GetType()
      Dim arrayMemberInfo() As MemberInfo
      Dim arrayMethodInfo() As MethodInfo
         ' Get the methods implemented in 'IDeserializationCallback' interface.
         arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods()
         Console.WriteLine(ControlChars.Cr + "Methods of 'IDeserializationCallback' Interface :")
         Dim index As Integer
         For index = 0 To arrayMethodInfo.Length - 1
         Next index
         ' Get FullName for interface by using Ignore case search.
         Console.WriteLine(ControlChars.Cr + "Methods of 'IEnumerable' Interface")
         arrayMethodInfo = objType.GetInterface("ienumerable", True).GetMethods()
         For index = 0 To arrayMethodInfo.Length - 1
         Next index
         'Get the Interface methods for 'IDictionary' interface
         Dim interfaceMappingObj As InterfaceMapping
         interfaceMappingObj = objType.GetInterfaceMap(GetType(IDictionary))
         arrayMemberInfo = interfaceMappingObj.InterfaceMethods
         Console.WriteLine(ControlChars.Cr + "Hashtable class Implements the following IDictionary Interface methods :")
         For index = 0 To arrayMemberInfo.Length - 1
         Next index
      Catch e As Exception
         Console.WriteLine(("Exception : " + e.ToString()))
      End Try
   End Sub 'Main
End Class 'MyInterfaceClass 

.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top