_Type.FindInterfacesとは? わかりやすく解説

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

静的初期化子が呼び出され、例外をスローします。

解説解説

このメソッドは、派生クラスでオーバーライドできます。

System.Reflection.TypeFilter デリゲートの代わりに、System.Reflection.Module クラスによって提供された Module.FilterTypeName デリゲートおよび Module.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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

_Type.FindInterfaces メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

COM オブジェクトに、Type.FindInterfaces メソッドへのバージョンに依存しないアクセスが用意されています。

このメソッドは、CLS に準拠していません。  

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

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)
Type[] FindInterfaces (
    TypeFilter filter,
    Object filterCriteria
)
array<Type^>^ FindInterfaces (
    TypeFilter^ filter, 
    Object^ filterCriteria
)
Type[] FindInterfaces (
    TypeFilter filter, 
    Object filterCriteria
)
function FindInterfaces (
    filter : TypeFilter, 
    filterCriteria : Object
) : Type[]

パラメータ

filter

インターフェイスを filterCriteria と比較する TypeFilter デリゲート。

filterCriteria

返される配列に、検出したインターフェイスを含めるかどうかを判断する検索条件。

戻り値
現在の Type によって実装または継承されているインターフェイスのフィルタ適用済みリストを表す、Type オブジェクトの配列。 または フィルタ条件に一致するインターフェイスが現在の Type で実装または継承されていない場合は、Type 型の空の配列。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「_Type.FindInterfaces」の関連用語

_Type.FindInterfacesのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



_Type.FindInterfacesのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS