This documentation is archived and is not being maintained.
Type.GetInterface Method
.NET Framework 1.1
Gets a specific interface implemented or inherited by the current Type.
Overload List
Searches for the interface with the specified name.
[Visual Basic] Overloads Public Function GetInterface(String) As Type
[C#] public Type GetInterface(string);
[C++] public: Type* GetInterface(String*);
[JScript] public function GetInterface(String) : Type;
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(String, Boolean) As Type
[C#] public abstract Type GetInterface(string, bool);
[C++] public: virtual Type* GetInterface(String*, bool) = 0;
[JScript] public abstract function GetInterface(String, Boolean) : Type;
Example
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of GetInterface. For other examples that might be available, see the individual overload topics.
[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.
See Also
Show: