Searches for the interface with the specified name.
Assembly: mscorlib (in mscorlib.dll)
Public Function GetInterface ( _
name As String _
) As Typepublic Type GetInterface(
string name
)public:
virtual Type^ GetInterface(
String^ name
) sealedabstract GetInterface :
name:string -> Type
override GetInterface :
name:string -> Type Parameters
- name
- Type: System
. . :: . String
The string containing the name of the interface to get. For generic interfaces, this is the mangled name.
Return Value
Type: SystemAn object representing the interface with the specified name, implemented or inherited by the current Type, if found; otherwise,
Implements
_Type| Exception | Condition |
|---|---|
| ArgumentNullException | name is |
| AmbiguousMatchException | The current Type represents a type that implements the same generic interface with different type arguments. |
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". |
The following code example uses the GetInterface(String) method to search the Hashtable class for the IDeserializationCallback interface, and lists the methods of the interface.
The code example also demonstrates the GetInterface(String, Boolean) 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
Try
' 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
Console.WriteLine(arrayMethodInfo(index).ToString())
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
Console.WriteLine(arrayMethodInfo(index).ToString())
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
Console.WriteLine(arrayMemberInfo(index).ToString())
Next index
Catch e As Exception
Console.WriteLine(("Exception : " + e.ToString()))
End Try
End Sub 'Main
End Class 'MyInterfaceClass
public static void Main()
{
Hashtable hashtableObj = new Hashtable();
Type objType = hashtableObj.GetType();
MemberInfo[] arrayMemberInfo;
MethodInfo[] arrayMethodInfo;
try
{
// Get the methods implemented in 'IDeserializationCallback' interface.
arrayMethodInfo =objType.GetInterface("IDeserializationCallback").GetMethods();
Console.WriteLine ("\nMethods of 'IDeserializationCallback' Interface :");
for(int index=0;index < arrayMethodInfo.Length ;index++)
Console.WriteLine (arrayMethodInfo[index].ToString() );
// Get FullName for interface by using Ignore case search.
Console.WriteLine ("\nMethods of 'IEnumerable' Interface");
arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods();
for(int index=0;index < arrayMethodInfo.Length ;index++)
Console.WriteLine (arrayMethodInfo[index].ToString());
//Get the Interface methods for 'IDictionary' interface
InterfaceMapping interfaceMappingObj;
interfaceMappingObj = objType.GetInterfaceMap(typeof(IDictionary));
arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
Console.WriteLine ("\nHashtable class Implements the following IDictionary Interface methods :");
for(int index=0; index < arrayMemberInfo.Length; index++)
Console.WriteLine (arrayMemberInfo[index].ToString() );
}
catch (Exception e)
{
Console.WriteLine ("Exception : " + e.ToString());
}
}
int main()
{
Hashtable^ hashtableObj = gcnew Hashtable;
Type^ objType = hashtableObj->GetType();
array<MemberInfo^>^arrayMemberInfo;
array<MethodInfo^>^arrayMethodInfo;
try
{
// Get the methods implemented in 'IDeserializationCallback' interface.
arrayMethodInfo = objType->GetInterface( "IDeserializationCallback" )->GetMethods();
Console::WriteLine( "\nMethods of 'IDeserializationCallback' Interface :" );
for ( int index = 0; index < arrayMethodInfo->Length; index++ )
Console::WriteLine( arrayMethodInfo[ index ] );
// Get FullName for interface by using Ignore case search.
Console::WriteLine( "\nMethods of 'IEnumerable' Interface" );
arrayMethodInfo = objType->GetInterface( "ienumerable", true )->GetMethods();
for ( int index = 0; index < arrayMethodInfo->Length; index++ )
Console::WriteLine( arrayMethodInfo[ index ] );
//Get the Interface methods for 'IDictionary*' interface
InterfaceMapping interfaceMappingObj;
interfaceMappingObj = objType->GetInterfaceMap( IDictionary::typeid );
arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
Console::WriteLine( "\nHashtable class Implements the following IDictionary Interface methods :" );
for ( int index = 0; index < arrayMemberInfo->Length; index++ )
Console::WriteLine( arrayMemberInfo[ index ] );
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception : {0}", e );
}
}
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note