Type.FindInterfaces(TypeFilter, Object) Type.FindInterfaces(TypeFilter, Object) Type.FindInterfaces(TypeFilter, Object) Type.FindInterfaces(TypeFilter, Object) Method

Definizione

Restituisce una matrice di oggetti Type che rappresenta un elenco filtrato di interfacce implementate o ereditate dall'oggetto Type corrente.Returns an array of Type objects representing a filtered list of interfaces implemented or inherited by the current Type.

public:
 virtual cli::array <Type ^> ^ FindInterfaces(System::Reflection::TypeFilter ^ filter, System::Object ^ filterCriteria);
public virtual Type[] FindInterfaces (System.Reflection.TypeFilter filter, object filterCriteria);
abstract member FindInterfaces : System.Reflection.TypeFilter * obj -> Type[]
override this.FindInterfaces : System.Reflection.TypeFilter * obj -> Type[]
Public Overridable Function FindInterfaces (filter As TypeFilter, filterCriteria As Object) As Type()

Parametri

filter
TypeFilter TypeFilter TypeFilter TypeFilter

Delegato che confronta le interfacce con filterCriteria.The delegate that compares the interfaces against filterCriteria.

filterCriteria
Object Object Object Object

Criteri di ricerca che determinano se un'interfaccia deve essere inclusa nella matrice restituita.The search criteria that determines whether an interface should be included in the returned array.

Restituisce

Type[]

Matrice di oggetti Type che rappresenta un elenco filtrato delle interfacce implementate o ereditate dall'oggetto Type corrente oppure matrice vuota se l'oggetto Type corrente non ha implementato né ereditato interfacce che corrispondono al filtro.An array of Type objects representing a filtered list of the interfaces implemented or inherited by the current Type, or an empty array if no interfaces matching the filter are implemented or inherited by the current Type.

Implementazioni

Eccezioni

Un inizializzatore statico viene richiamato e genera un'eccezione.A static initializer is invoked and throws an exception.

Esempi

Nell'esempio seguente viene trovata l'interfaccia specificata implementata o ereditata dal tipo specificato, quindi vengono visualizzati i nomi di interfaccia.The following example finds the specified interface implemented or inherited by the specified type, and then displays the interface names.

#using <system.xml.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Reflection;
public ref class MyFindInterfacesSample
{
public:
    static bool MyInterfaceFilter(Type^ typeObj, Object^ criteriaObj)
    {
        if(typeObj->ToString()->Equals(criteriaObj->ToString()))
            return true;
        else
            return false;
   }
};

int main()
{
    try
    {
        XmlDocument^ myXMLDoc = gcnew XmlDocument;
        myXMLDoc->LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" 
            + "<title>Pride And Prejudice</title> </book>");
        Type^ myType = myXMLDoc->GetType();
      
        // Specify the TypeFilter delegate that compares the interfaces 
        // against filter criteria.
        TypeFilter^ myFilter = gcnew TypeFilter( 
            MyFindInterfacesSample::MyInterfaceFilter);
        array<String^>^myInterfaceList = {"System.Collections.IEnumerable",
            "System.Collections.ICollection"};
        for(int index = 0; index < myInterfaceList->Length; index++)
        {
            array<Type^>^myInterfaces = myType->FindInterfaces( 
                myFilter, myInterfaceList[index]);
            if(myInterfaces->Length > 0)
            {
                Console::WriteLine("\n{0} implements the interface {1}.", 
                    myType, myInterfaceList[index]);
                for(int j = 0; j < myInterfaces->Length; j++)
                Console::WriteLine("Interfaces supported: {0}.",
                    myInterfaces[j]);
            }
            else
                Console::WriteLine(
                    "\n{0} does not implement the interface {1}.", 
                    myType, myInterfaceList[index]);

        }
    }
    catch(ArgumentNullException^ e) 
    {
        Console::WriteLine("ArgumentNullException: {0}", e->Message);
    }
    catch(TargetInvocationException^ e) 
    {
        Console::WriteLine("TargetInvocationException: {0}", e->Message);
    }
    catch(Exception^ e) 
    {
        Console::WriteLine("Exception: {0}", e->Message);
    }
}

using System;
using System.Xml;
using System.Reflection;

public class MyFindInterfacesSample 
{
    public static void Main()
    {
        try
        {
            XmlDocument myXMLDoc = new XmlDocument();
            myXMLDoc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" + "</book>");
            Type myType = myXMLDoc.GetType();

            // Specify the TypeFilter delegate that compares the 
            // interfaces against filter criteria.
            TypeFilter myFilter = new TypeFilter(MyInterfaceFilter);
            String[] myInterfaceList = new String[2] 
                {"System.Collections.IEnumerable", 
                "System.Collections.ICollection"};
            for(int index=0; index < myInterfaceList.Length; index++)
            {
                Type[] myInterfaces = myType.FindInterfaces(myFilter, 
                    myInterfaceList[index]);
                if (myInterfaces.Length > 0) 
                {
                    Console.WriteLine("\n{0} implements the interface {1}.",
                        myType, myInterfaceList[index]);	
                    for(int j =0;j < myInterfaces.Length;j++)
                        Console.WriteLine("Interfaces supported: {0}.", 
                            myInterfaces[j].ToString());
                }
                else
                    Console.WriteLine(
                        "\n{0} does not implement the interface {1}.", 
                        myType,myInterfaceList[index]);	
            }
        }
        catch(ArgumentNullException e)
        {
            Console.WriteLine("ArgumentNullException: " + e.Message);
        }
        catch(TargetInvocationException e)
        {
            Console.WriteLine("TargetInvocationException: " + e.Message);
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
        }
    }
      
    public static bool MyInterfaceFilter(Type typeObj,Object criteriaObj)
    {
        if(typeObj.ToString() == criteriaObj.ToString())
            return true;
        else
            return false;
    }
}

Imports System.Xml
Imports System.Reflection

Public Class MyFindInterfacesSample
    Public Shared Sub Main()
        Try
            Dim myXMLDoc As New XmlDocument()
            myXMLDoc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" _
                & "<title>Pride And Prejudice</title>" & "</book>")
            Dim myType As Type = myXMLDoc.GetType()

            ' Specify the TypeFilter delegate that compares the 
            ' interfaces against filter criteria.
            Dim myFilter As New TypeFilter(AddressOf MyInterfaceFilter)
            Dim myInterfaceList() As String = _
                {"System.Collections.IEnumerable", _
                "System.Collections.ICollection"}
            Dim index As Integer
            For index = 0 To myInterfaceList.Length - 1
                Dim myInterfaces As Type() = _
                    myType.FindInterfaces(myFilter, myInterfaceList(index))
                If myInterfaces.Length > 0 Then
                    Console.WriteLine(ControlChars.Cr & _
                        "{0} implements the interface {1}.", _
                        myType, myInterfaceList(index))
                    Dim j As Integer
                    For j = 0 To myInterfaces.Length - 1
                        Console.WriteLine("Interfaces supported: {0}", _
                            myInterfaces(j).ToString())
                    Next j
                Else
                    Console.WriteLine(ControlChars.Cr & _
                        "{0} does not implement the interface {1}.", _
                        myType, myInterfaceList(index))
                End If
            Next index
        Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException: " & e.Message)
        Catch e As TargetInvocationException
            Console.WriteLine("TargetInvocationException: " & e.Message)
        Catch e As Exception
            Console.WriteLine("Exception: " & e.Message)
        End Try
    End Sub
    Public Shared Function MyInterfaceFilter(ByVal typeObj As Type, _
        ByVal criteriaObj As [Object]) As Boolean
        If typeObj.ToString() = criteriaObj.ToString() Then
            Return True
        Else
            Return False
        End If
    End Function 'MyInterfaceFilter 
End Class 'MyFindInterfacesSample

Commenti

Questo metodo può essere sottoposto a override da una classe derivata.This method can be overridden by a derived class.

È Module.FilterTypeName Module.FilterTypeNameIgnoreCase anchepossibileSystem.Reflection.Module usare i delegati e forniti dalla classe, invece del delegato.System.Reflection.TypeFilterThe Module.FilterTypeName and Module.FilterTypeNameIgnoreCase delegates supplied by the System.Reflection.Module class may also be used, in lieu of the System.Reflection.TypeFilter delegate.

Tutte le interfacce implementate da questa classe vengono considerate durante la ricerca, se dichiarate da una classe base o da questa classe.All of the interfaces implemented by this class are considered during the search, whether declared by a base class or this class itself.

Questo metodo esegue la ricerca nella gerarchia della classe di base, restituendo ogni interfaccia corrispondente implementata da ogni classe, nonché tutte le interfacce di corrispondenza implementate da ognuna di queste interfacce (ovvero viene restituita la chiusura transitiva delle interfacce corrispondenti).This method searches the base class hierarchy, returning each of the matching interfaces each class implements as well as all the matching interfaces each of those interfaces implements (that is, the transitive closure of the matching interfaces is returned). Non viene restituita alcuna interfaccia duplicata.No duplicate interfaces are returned.

Se l'oggetto Type corrente rappresenta un parametro di tipo nella definizione di un tipo o di un metodo FindInterfaces generico, Cerca tutte le interfacce dichiarate nei vincoli sul parametro di tipo e tutte le interfacce ereditate tramite le interfacce. dichiarata nei vincoli.If the current Type represents a type parameter in the definition of a generic type or generic method, FindInterfaces searches all the interfaces declared in the constraints on the type parameter, and all interfaces inherited through the interfaces declared in the constraints. Se l'oggetto Type corrente rappresenta un argomento di tipo di un tipo FindInterfaces generico, Cerca tutte le interfacce implementate dal tipo, indipendentemente dal fatto che corrispondano o meno a vincoli.If the current Type represents a type argument of a generic type, FindInterfaces searches all the interfaces implemented by the type, whether or not they match constraints.

Nota

FindInterfacespuò restituire interfacce generiche, anche su tipi non generici.FindInterfaces can return generic interfaces, even on types that are not generic. Un tipo non generico, ad esempio, potrebbe IEnumerable<int> implementareIEnumerable(Of Integer) (in Visual Basic).For example, a nongeneric type might implement IEnumerable<int> (IEnumerable(Of Integer) in Visual Basic).

Si applica a

Vedi anche