Type.GetInterface Method (String, Boolean)
When overridden in a derived class, searches for the specified interface, specifying whether to do a case-sensitive search.
[Visual Basic] Overloads Public MustOverride Function GetInterface( _ ByVal name As String, _ ByVal ignoreCase As Boolean _ ) As Type [C#] public abstract Type GetInterface( string name, bool ignoreCase ); [C++] public: virtual Type* GetInterface( String* name, bool ignoreCase ) = 0; [JScript] public abstract function GetInterface( name : String, ignoreCase : Boolean ) : Type;
Parameters
- name
- The String containing the name of the interface to get.
- ignoreCase
- true to perform a case-insensitive search for name.
-or-
false to perform a case-sensitive search for name.
Return Value
A Type object representing the interface with the specified name, implemented or inherited by the current Type, if found; otherwise, a null reference (Nothing in Visual Basic).
Exceptions
| Exception Type | Condition |
|---|---|
| ArgumentNullException | name is a null reference (Nothing in Visual Basic). |
Example
[Visual Basic] 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 [C#] 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()); } } [C++] int main() { Hashtable* hashtableObj = new Hashtable(); Type* objType = hashtableObj->GetType(); MemberInfo* arrayMemberInfo[]; MethodInfo* arrayMethodInfo[]; try { // Get the methods implemented in 'IDeserializationCallback' interface. arrayMethodInfo =objType->GetInterface(S"IDeserializationCallback")->GetMethods(); Console::WriteLine (S"\nMethods of 'IDeserializationCallback' Interface :"); for (int index=0;index < arrayMethodInfo->Length ;index++) Console::WriteLine (arrayMethodInfo->Item[index]); // Get FullName for interface by using Ignore case search. Console::WriteLine (S"\nMethods of 'IEnumerable' Interface"); arrayMethodInfo = objType->GetInterface(S"ienumerable", true)->GetMethods(); for (int index=0;index < arrayMethodInfo->Length ;index++) Console::WriteLine (arrayMethodInfo->Item[index]); //Get the Interface methods for 'IDictionary*' interface InterfaceMapping interfaceMappingObj; interfaceMappingObj = objType->GetInterfaceMap(__typeof(IDictionary)); arrayMemberInfo = interfaceMappingObj.InterfaceMethods; Console::WriteLine (S"\nHashtable class Implements the following IDictionary Interface methods :"); for (int index=0; index < arrayMemberInfo->Length; index++) Console::WriteLine (arrayMemberInfo->Item[index]); } catch (Exception* e) { Console::WriteLine (S"Exception : {0}", e); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard
See Also
Type Class | Type Members | System Namespace | Type.GetInterface Overload List | String | GetInterfaces | FindInterfaces