Type.GetInterface Método

Definición

Obtiene una interfaz específica implementada o heredada por el objeto Type actual.

Sobrecargas

GetInterface(String)

Busca la interfaz con el nombre especificado.

GetInterface(String, Boolean)

Cuando se invalida en una clase derivada, busca la interfaz especificada e indica si la búsqueda no debe distinguir entre mayúsculas y minúsculas para el nombre de la interfaz.

GetInterface(String)

Busca la interfaz con el nombre especificado.

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

Parámetros

name
String

Cadena que contiene el nombre de la interfaz que se va a obtener. Para las interfaces genéricas, este es el nombre con sufijo.

Devoluciones

Objeto que representa la interfaz con el nombre especificado, implementada o heredada por el objeto Type actual, si se encuentra; de lo contrario, null.

Implementaciones

Excepciones

name es null.

El Type actual representa un tipo que implementa la misma interfaz genérica con argumentos de tipo diferente.

Ejemplos

En el ejemplo de código siguiente se usa el GetInterface(String) método para buscar la Hashtable clase de la IDeserializationCallback interfaz y se enumeran los métodos de la interfaz .

El ejemplo de código también muestra la sobrecarga del GetInterface(String, Boolean) método y el GetInterfaceMap método .

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());
    }
}
let hashtableObj = Hashtable()
let objType = hashtableObj.GetType()
try
    // Get the methods implemented in 'IDeserializationCallback' interface.
    let arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods()
    printfn "\nMethods of 'IDeserializationCallback' Interface :"
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    // Get FullName for interface by using Ignore case search.
    printfn "\nMethods of 'IEnumerable' Interface"
    let arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods()
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    //Get the Interface methods for 'IDictionary' interface
    let interfaceMappingObj = objType.GetInterfaceMap typeof<IDictionary>
    let arrayMemberInfo = interfaceMappingObj.InterfaceMethods
    printfn "\nHashtable class Implements the following IDictionary Interface methods :"
    for memberInfo in arrayMemberInfo do
        printfn $"{memberInfo}"
with e ->
    printfn $"Exception : {e}"
   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

Comentarios

La búsqueda name distingue mayúsculas de minúsculas.

Si el objeto actual Type representa un tipo genérico construido, este método devuelve con Type los parámetros de tipo reemplazados por los argumentos de tipo adecuados.

Si el objeto actual Type representa un parámetro de tipo en la definición de un tipo genérico o un método genérico, este método busca en las restricciones de interfaz y las interfaces heredadas de las restricciones de clase o interfaz.

Nota:

En el caso de las interfaces genéricas, el name parámetro es el nombre mangled, que termina con un acento grave (') y el número de parámetros de tipo. Esto se aplica tanto a las definiciones de interfaz genéricas como a las interfaces genéricas construidas. Por ejemplo, para buscar IExample<T> (IExample(Of T) en Visual Basic) o IExample<string> (IExample(Of String) en Visual Basic), busque "IExample`1".

Consulte también

Se aplica a

GetInterface(String, Boolean)

Cuando se invalida en una clase derivada, busca la interfaz especificada e indica si la búsqueda no debe distinguir entre mayúsculas y minúsculas para el nombre de la interfaz.

public:
 abstract Type ^ GetInterface(System::String ^ name, bool ignoreCase);
public abstract Type? GetInterface (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

Cadena que contiene el nombre de la interfaz que se va a obtener. Para las interfaces genéricas, este es el nombre con sufijo.

ignoreCase
Boolean

true para omitir la grafía de la parte de name que especifica el nombre de interfaz simple (se debe respetar la grafía de la parte que especifica el espacio de nombres).

O bien

false para realizar una búsqueda de todas las partes de name que distinga mayúsculas de minúsculas.

Devoluciones

Objeto que representa la interfaz con el nombre especificado, implementada o heredada por el objeto Type actual, si se encuentra; de lo contrario, null.

Implementaciones

Excepciones

name es null.

El Type actual representa un tipo que implementa la misma interfaz genérica con argumentos de tipo diferente.

Ejemplos

En el ejemplo de código siguiente se usa el GetInterface(String, Boolean) método para realizar una búsqueda sin distinción entre mayúsculas y minúsculas de la Hashtable clase para la IEnumerable interfaz .

El ejemplo de código también muestra la sobrecarga del GetInterface(String) método y el GetInterfaceMap método .

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());
    }
}
let hashtableObj = Hashtable()
let objType = hashtableObj.GetType()
try
    // Get the methods implemented in 'IDeserializationCallback' interface.
    let arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods()
    printfn "\nMethods of 'IDeserializationCallback' Interface :"
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    // Get FullName for interface by using Ignore case search.
    printfn "\nMethods of 'IEnumerable' Interface"
    let arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods()
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    //Get the Interface methods for 'IDictionary' interface
    let interfaceMappingObj = objType.GetInterfaceMap typeof<IDictionary>
    let arrayMemberInfo = interfaceMappingObj.InterfaceMethods
    printfn "\nHashtable class Implements the following IDictionary Interface methods :"
    for memberInfo in arrayMemberInfo do
        printfn $"{memberInfo}"
with e ->
    printfn $"Exception : {e}"
   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

Comentarios

El ignoreCase parámetro solo se aplica al nombre de interfaz simple, no al espacio de nombres . La parte de que especifica el espacio de name nombres debe tener el caso correcto o no se encontrará la interfaz. Por ejemplo, la cadena "System.icomparable" busca la IComparable interfaz, pero la cadena "system.icomparable" no lo hace.

Si el objeto actual Type representa un tipo genérico construido, este método devuelve con Type los parámetros de tipo reemplazados por los argumentos de tipo adecuados.

Si el objeto actual Type representa un parámetro de tipo en la definición de un tipo genérico o un método genérico, este método busca en las restricciones de interfaz y las interfaces heredadas de las restricciones de clase o interfaz.

Nota

En el caso de las interfaces genéricas, el name parámetro es el nombre mangled, que termina con un acento grave (') y el número de parámetros de tipo. Esto se aplica tanto a las definiciones de interfaz genéricas como a las interfaces genéricas construidas. Por ejemplo, para buscar IExample<T> (IExample(Of T) en Visual Basic) o IExample<string> (IExample(Of String) en Visual Basic), busque "IExample`1".

Consulte también

Se aplica a