Type.FindInterfaces 메서드

현재 Type에 의해 구현되거나 상속되는 인터페이스의 필터링된 목록을 나타내는 Type 개체의 배열을 반환합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Overridable Function FindInterfaces ( _
    filter As TypeFilter, _
    filterCriteria As Object _
) As Type()
‘사용 방법
Dim instance As Type
Dim filter As TypeFilter
Dim filterCriteria As Object
Dim returnValue As Type()

returnValue = instance.FindInterfaces(filter, filterCriteria)
public virtual Type[] FindInterfaces (
    TypeFilter filter,
    Object filterCriteria
)
public:
virtual array<Type^>^ FindInterfaces (
    TypeFilter^ filter, 
    Object^ filterCriteria
)
public Type[] FindInterfaces (
    TypeFilter filter, 
    Object filterCriteria
)
public function FindInterfaces (
    filter : TypeFilter, 
    filterCriteria : Object
) : Type[]

매개 변수

  • filter
    인터페이스를 filterCriteria에 비교하는 TypeFilter 대리자입니다.
  • filterCriteria
    반환되는 배열에 인터페이스가 포함되어야 하는지 여부를 결정하는 검색 조건입니다.

반환 값

현재 Type에 의해 구현되거나 상속된 인터페이스의 필터링된 목록을 나타내는 Type 개체의 배열입니다. 해당 필터와 일치하는 인터페이스 중에서 현재 Type에 의해 구현되거나 상속된 인터페이스가 없는 경우에는 Type 형식의 빈 배열입니다.

예외

예외 형식 조건

ArgumentNullException

filter가 Null 참조(Visual Basic의 경우 Nothing)인 경우

TargetInvocationException

정적 이니셜라이저가 호출되고 예외를 throw하는 경우

설명

이 메서드는 파생된 클래스에서 재정의할 수 있습니다.

System.Reflection.TypeFilter 대리자 대신, System.Reflection.Module 클래스에서 제공하는 Module.FilterTypeNameModule.FilterTypeNameIgnoreCase 대리자를 사용할 수도 있습니다.

검색 도중에는 기본 클래스에 의해 선언되거나 이 클래스 자체에 의해 선언됨에 상관 없이 이 클래스에 의해 구현되는 모든 인터페이스가 검색 대상이 됩니다.

이 메서드는 기본 클래스 계층 구조를 검색하여 각 클래스가 구현하는 인터페이스 중에서 검색 조건과 일치하는 각 인터페이스와, 검색된 각 인터페이스가 구현하는 인터페이스 중에서 검색 조건과 일치하는 모든 인터페이스를 반환합니다. 즉, 전이적 검색의 최종 단계에 있는 인터페이스가 반환됩니다. 중복된 인터페이스는 반환되지 않습니다.

현재 Type이 제네릭 형식 또는 제네릭 메서드 정의의 형식 매개 변수를 나타내는 경우 FindInterfaces는 형식 매개 변수에 대한 제약 조건에 선언된 모든 인터페이스와 제약 조건에 선언된 인터페이스를 통해 상속된 모든 인터페이스를 검색합니다. 현재 Type이 제네릭 형식의 형식 인수를 나타내는 경우 FindInterfaces는 제약 조건과 일치하는지 여부에 관계없이 해당 형식이 구현하는 모든 인터페이스를 검색합니다.

참고

FindInterfaces는 제네릭이 아닌 형식에서도 제네릭 인터페이스를 반환할 수 있습니다. 예를 들어, 제네릭이 아닌 형식이 IEnumerable<int>(Visual Basic의 경우 IEnumerable(Of Integer))을 구현할 수 있습니다.

예제

다음 예제에서는 지정된 형식에 의해 상속되거나 구현된 특정 인터페이스를 찾고 이 인터페이스의 이름을 표시합니다.

Imports System
Imports System.Xml
Imports System.Reflection
Imports Microsoft.VisualBasic

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 'Main
    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
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;
    }
}
#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);
    }
}
import System.*;
import System.Xml.*;
import System.Reflection.*;

public class MyFindInterfacesSample
{
    public static void main(String[] args)
    {
        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[] { 
                "System.Collections.IEnumerable",
                "System.Collections.ICollection" };
            for (int index = 0; index < myInterfaceList.length; index++) {
                Type myInterfaces[] = myType.FindInterfaces(myFilter,
                     myInterfaceList.get_Item(index));
                if (myInterfaces.length > 0) {
                    Console.WriteLine("\n{0} implements the interface {1}.",
                        myType, myInterfaceList.get_Item(index));
                    for (int j = 0; j < myInterfaces.length; j++) {
                        Console.WriteLine("Interfaces supported: {0}.",
                            myInterfaces.get_Item(j).ToString());
                    }
                }
                else {
                    Console.WriteLine("\n{0} does not implement the"
                        + " interface {1}.", myType,
                        myInterfaceList.get_Item(index));
                }
            }
        }
        catch (ArgumentNullException e) {
            Console.WriteLine("ArgumentNullException: " + e.get_Message());
        }
        catch (TargetInvocationException e) {
            Console.WriteLine("TargetInvocationException: " + e.get_Message());
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception: " + e.get_Message());
        }
    } //main

    public static boolean MyInterfaceFilter(Type typeObj, Object criteriaObj)
    {
        if (typeObj.ToString().Equals(criteriaObj.ToString())) {
            return true;
        }
        else {
            return false;
        }
    } //MyInterfaceFilter
} //MyFindInterfacesSample

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

Type 클래스
Type 멤버
System 네임스페이스
Module
TypeFilter
GetInterface
GetInterfaces