Type.GetInterface Método

Definição

Obtém uma interface específica implementada ou herdada pelo Type atual.Gets a specific interface implemented or inherited by the current Type.

Sobrecargas

GetInterface(String)

Pesquisa a interface com o nome especificado.Searches for the interface with the specified name.

GetInterface(String, Boolean)

Quando substituído em uma classe derivada, procura pela interface especificada, indicando se deseja fazer uma pesquisa que não diferencia maiúsculas de minúsculas pelo nome da interface.When overridden in a derived class, searches for the specified interface, specifying whether to do a case-insensitive search for the interface name.

GetInterface(String)

Pesquisa a interface com o nome especificado.Searches for the interface with the specified name.

public:
 virtual Type ^ GetInterface(System::String ^ name);
public Type GetInterface (string name);
abstract member GetInterface : string -> Type
override this.GetInterface : string -> Type
Public Function GetInterface (name As String) As Type

Parâmetros

name
String

A cadeia de caracteres que contém o nome da interface a ser obtida.The string containing the name of the interface to get. Para interfaces genéricas, este é o nome danificado.For generic interfaces, this is the mangled name.

Retornos

Um objeto que representa a interface com o nome especificado, implementado ou herdado pelo Type atual, se encontrado; caso contrário, null.An object representing the interface with the specified name, implemented or inherited by the current Type, if found; otherwise, null.

Implementações

Exceções

name é null.name is null.

O Type atual representa um tipo que implementa a mesma interface genérica com argumentos de tipo diferente.The current Type represents a type that implements the same generic interface with different type arguments.

Exemplos

O exemplo de código a seguir usa o método GetInterface(String) para pesquisar a classe Hashtable para a interface IDeserializationCallback e lista os métodos da interface.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.

O exemplo de código também demonstra a sobrecarga do método GetInterface(String, Boolean) e o método GetInterfaceMap.The code example also demonstrates the GetInterface(String, Boolean) method overload and the GetInterfaceMap method.

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 );
   }
}
public static void Main()
{
    Hashtable hashtableObj = new Hashtable();
    Type objType = hashtableObj.GetType();
    MethodInfo[] arrayMethodInfo;
    MemberInfo[] arrayMemberInfo;
    try
    {   
        // Get the methods implemented in 'IDeserializationCallback' interface.
        arrayMethodInfo =objType.GetInterface("IDeserializationCallback").GetMethods();
        Console.WriteLine ("\nMethods of 'IDeserializationCallback' Interface :");
        foreach(MethodInfo methodInfo in arrayMethodInfo)
            Console.WriteLine (methodInfo); 

        // Get FullName for interface by using Ignore case search.
        Console.WriteLine ("\nMethods of 'IEnumerable' Interface");
        arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods();
        foreach(MethodInfo methodInfo in arrayMethodInfo)
           Console.WriteLine (methodInfo); 
       
        //Get the Interface methods for 'IDictionary' interface
        InterfaceMapping interfaceMappingOb = objType.GetInterfaceMap(typeof(IDictionary));
        arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
        Console.WriteLine ("\nHashtable class Implements the following IDictionary Interface methods :");
        foreach(MemberInfo memberInfo in arrayMemberInfo)
           Console.WriteLine (memberInfo); 
    }
    catch (Exception e)
    {
        Console.WriteLine ("Exception : " + e.ToString());            
    }                 
}
   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
End Class

Comentários

A pesquisa de name diferencia maiúsculas de minúsculas.The search for name is case-sensitive.

Caso o Type atual represente um tipo genérico construído, este método retorna o Type com os parâmetros de tipo substituídos pelos argumentos de tipo apropriados.If the current Type represents a constructed generic type, this method returns the Type with the type parameters replaced by the appropriate type arguments.

Se a Type atual representar um parâmetro de tipo na definição de um tipo genérico ou um método genérico, esse método pesquisará as restrições de interface e todas as interfaces herdadas das restrições de classe ou de interface.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.

Observação

Para interfaces genéricas, o parâmetro name é o nome desconfigurado, terminando com um acento grave (`) e o número de parâmetros de tipo.For generic interfaces, the name parameter is the mangled name, ending with a grave accent (`) and the number of type parameters. Isso é verdadeiro para as definições de interface genérica e interfaces genéricas construídas.This is true for both generic interface definitions and constructed generic interfaces. Por exemplo, para localizar IExample<T> (IExample(Of T) em Visual Basic) ou IExample<string> (IExample(Of String) em Visual Basic), pesquise "IExample`1".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".

Veja também

GetInterface(String, Boolean)

Quando substituído em uma classe derivada, procura pela interface especificada, indicando se deseja fazer uma pesquisa que não diferencia maiúsculas de minúsculas pelo nome da interface.When overridden in a derived class, searches for the specified interface, specifying whether to do a case-insensitive search for the interface name.

public:
 abstract Type ^ GetInterface(System::String ^ name, bool ignoreCase);
public abstract Type GetInterface (string name, bool ignoreCase);
abstract member GetInterface : string * bool -> Type
Public MustOverride Function GetInterface (name As String, ignoreCase As Boolean) As Type

Parâmetros

name
String

A cadeia de caracteres que contém o nome da interface a ser obtida.The string containing the name of the interface to get. Para interfaces genéricas, este é o nome danificado.For generic interfaces, this is the mangled name.

ignoreCase
Boolean

true para ignorar a diferença entre maiúsculas e minúsculas dessa parte de name que especifica o nome da interface simples (a parte que especifica se o namespace deve diferenciar maiúsculas e minúsculas corretamente).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).

- ou --or- false para realizar uma pesquisa que diferencia maiúsculas de minúsculas para todas as partes de name.false to perform a case-sensitive search for all parts of name.

Retornos

Um objeto que representa a interface com o nome especificado, implementado ou herdado pelo Type atual, se encontrado; caso contrário, null.An object representing the interface with the specified name, implemented or inherited by the current Type, if found; otherwise, null.

Implementações

Exceções

name é null.name is null.

O Type atual representa um tipo que implementa a mesma interface genérica com argumentos de tipo diferente.The current Type represents a type that implements the same generic interface with different type arguments.

Exemplos

O exemplo de código a seguir usa o método GetInterface(String, Boolean) para executar uma pesquisa que não diferencia maiúsculas de minúsculas da classe Hashtable para a interface IEnumerable.The following code example uses the GetInterface(String, Boolean) method to perform a case-insensitive search of the Hashtable class for the IEnumerable interface.

O exemplo de código também demonstra a sobrecarga do método GetInterface(String) e o método GetInterfaceMap.The code example also demonstrates the GetInterface(String) method overload and the GetInterfaceMap method.

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 );
   }
}
public static void Main()
{
    Hashtable hashtableObj = new Hashtable();
    Type objType = hashtableObj.GetType();
    MethodInfo[] arrayMethodInfo;
    MemberInfo[] arrayMemberInfo;
    try
    {   
        // Get the methods implemented in 'IDeserializationCallback' interface.
        arrayMethodInfo =objType.GetInterface("IDeserializationCallback").GetMethods();
        Console.WriteLine ("\nMethods of 'IDeserializationCallback' Interface :");
        foreach(MethodInfo methodInfo in arrayMethodInfo)
            Console.WriteLine (methodInfo); 

        // Get FullName for interface by using Ignore case search.
        Console.WriteLine ("\nMethods of 'IEnumerable' Interface");
        arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods();
        foreach(MethodInfo methodInfo in arrayMethodInfo)
           Console.WriteLine (methodInfo); 
       
        //Get the Interface methods for 'IDictionary' interface
        InterfaceMapping interfaceMappingOb = objType.GetInterfaceMap(typeof(IDictionary));
        arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
        Console.WriteLine ("\nHashtable class Implements the following IDictionary Interface methods :");
        foreach(MemberInfo memberInfo in arrayMemberInfo)
           Console.WriteLine (memberInfo); 
    }
    catch (Exception e)
    {
        Console.WriteLine ("Exception : " + e.ToString());            
    }                 
}
   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
End Class

Comentários

O parâmetro ignoreCase aplica-se somente ao nome de interface simples, não ao namespace.The ignoreCase parameter applies only to the simple interface name, not to the namespace. A parte de name que especifica o namespace deve ter o caso correto ou a interface não será encontrada.The portion of name that specifies the namespace must have the correct case, or the interface will not be found. Por exemplo, a cadeia de caracteres "System. IComparable" localiza a interface IComparable, mas a cadeia de caracteres "System. IComparable" não.For example, the string "System.icomparable" finds the IComparable interface, but the string "system.icomparable" does not.

Caso o Type atual represente um tipo genérico construído, este método retorna o Type com os parâmetros de tipo substituídos pelos argumentos de tipo apropriados.If the current Type represents a constructed generic type, this method returns the Type with the type parameters replaced by the appropriate type arguments.

Se a Type atual representar um parâmetro de tipo na definição de um tipo genérico ou um método genérico, esse método pesquisará as restrições de interface e todas as interfaces herdadas das restrições de classe ou de interface.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.

Observação

Para interfaces genéricas, o parâmetro name é o nome desconfigurado, terminando com um acento grave (`) e o número de parâmetros de tipo.For generic interfaces, the name parameter is the mangled name, ending with a grave accent (`) and the number of type parameters. Isso é verdadeiro para as definições de interface genérica e interfaces genéricas construídas.This is true for both generic interface definitions and constructed generic interfaces. Por exemplo, para localizar IExample<T> (IExample(Of T) em Visual Basic) ou IExample<string> (IExample(Of String) em Visual Basic), pesquise "IExample1 "".For example, to find IExample<T> (IExample(Of T) in Visual Basic) or IExample<string> (IExample(Of String) in Visual Basic), search for "IExample1"`.

Veja também

Aplica-se a