_Type.FindInterfaces メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > _Type.FindInterfaces メソッドの意味・解説 

_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 によって実装または継承されているインターフェイスフィルタ適用済みリストを表す、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

filternull 参照 (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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「_Type.FindInterfaces メソッド」の関連用語

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

   

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



_Type.FindInterfaces メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS