Type.GetInterfaces Type.GetInterfaces Type.GetInterfaces Type.GetInterfaces Method

Definição

Quando substituído em uma classe derivada, obtém todas as interfaces implementadas ou herdadas pelo Type atual.When overridden in a derived class, gets all the interfaces implemented or inherited by the current Type.

public:
 abstract cli::array <Type ^> ^ GetInterfaces();
public abstract Type[] GetInterfaces ();
abstract member GetInterfaces : unit -> Type[]
Public MustOverride Function GetInterfaces () As Type()

Retornos

Type[]

Uma matriz de objetos Type que representa todas as interfaces implementadas ou herdadas pela Type atual.An array of Type objects representing all the interfaces implemented or inherited by the current Type.

- ou --or- Uma matriz vazia do tipo Type, se nenhuma interface está implementada ou herdada pela Type atual.An empty array of type Type, if no interfaces are implemented or inherited by the current Type.

Implementações

Exceções

Um inicializador estático é invocado e lança uma exceção.A static initializer is invoked and throws an exception.

Exemplos

O exemplo a seguir obtém o tipo da classe especificada e exibe todas as interfaces que o tipo implementa ou herda.The following example gets the type of the specified class and displays all the interfaces that the type implements or inherits. Para compilar o exemplo de Visual Basic, use os seguintes comandos de compilador:To compile the Visual Basic example, use the following compiler commands:

vbc type_getinterfaces1.vb /r:System.Web.dll /r:System.dll

using namespace System;
using namespace System::Collections::Generic;

void main()
{
    Console::WriteLine("\r\nInterfaces implemented by Dictionary<int, String^>:\r\n");
     
    for each (Type^ tinterface in Dictionary<int, String^>::typeid->GetInterfaces())
    {
        Console::WriteLine(tinterface->ToString());
    }

    //Console::ReadLine()      // Uncomment this line for Visual Studio. 
}

/* This example produces output similar to the following:

Interfaces implemented by Dictionary<int, String^>:

System.Collections.Generic.IDictionary`2[System.Int32,System.String]
System.Collections.Generic.ICollection`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collection.IEnumerable
System.Collection.IDictionary
System.Collection.ICollection
System.Runtime.Serialization.ISerializable
System.Runtime.Serialization.IDeserializationCallback
 */
using System;
using System.Collections.Generic;

public class Example
{
    static void Main()
    {
        Console.WriteLine("\r\nInterfaces implemented by Dictionary<int, string>:\r\n");
        
        foreach (Type tinterface in typeof(Dictionary<int, string>).GetInterfaces())
        {
            Console.WriteLine(tinterface.ToString());
        }

        //Console.ReadLine()      // Uncomment this line for Visual Studio. 
    }
}

/* This example produces output similar to the following:

Interfaces implemented by Dictionary<int, string>:

System.Collections.Generic.IDictionary`2[System.Int32,System.String]
System.Collections.Generic.ICollection`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collection.IEnumerable
System.Collection.IDictionary
System.Collection.ICollection
System.Runtime.Serialization.ISerializable
System.Runtime.Serialization.IDeserializationCallback
 */
Imports System.Collections.Generic

Public Class Example

    Shared Sub Main()

        Console.WriteLine(vbCrLf & _
            "Interfaces implemented by Dictionary(Of Integer, String):" & vbCrLf)
        
        For Each tinterface As Type In GetType(Dictionary(Of Integer, String)).GetInterfaces()

            Console.WriteLine(tinterface.ToString())

        Next

        'Console.ReadLine()      ' Uncomment this line for Visual Studio. 
    End Sub
End Class

' This example produces output similar to the following:
'
'Interfaces implemented by Dictionary(Of Integer, String):
'System.Collections.Generic.IDictionary`2[System.Int32,System.String]
'System.Collections.Generic.ICollection`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
'System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
'System.Collection.IEnumerable
'System.Collection.IDictionary
'System.Collection.ICollection
'System.Runtime.Serialization.ISerializable
'System.Runtime.Serialization.IDeserializationCallback

Comentários

O GetInterfaces método não retorna interfaces em uma ordem específica, como ordem alfabética ou declaração.The GetInterfaces method does not return interfaces in a particular order, such as alphabetical or declaration order. Seu código não deve depender da ordem em que as interfaces são retornadas, pois essa ordem varia.Your code must not depend on the order in which interfaces are returned, because that order varies.

Se o atual Type representar um tipo genérico construído, esse método retornará os Type objetos 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 objects with the type parameters replaced by the appropriate type arguments.

Se Current Type 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 quaisquer interfaces herdadas de 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.

Aplica-se a

Veja também