英語で読む

次の方法で共有


Type.GetInterfaces メソッド

定義

派生クラスによってオーバーライドされた場合、現在の Type で実装または継承されているすべてのインターフェイスを取得します。

C#
public abstract Type[] GetInterfaces ();

戻り値

Type[]

現在の Type で実装または継承されているすべてのインターフェイスを表す Typeオブジェクトの配列。

または 現在の Type で実装または継承されているインターフェイスが存在しない場合は、Type 型の空の配列。

実装

例外

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

次の例では、指定したクラスの型を取得し、その型によって実装または継承されるすべてのインターフェイスを表示します。 Visual Basic の例をコンパイルするには、次のコンパイラコマンドを使用します。

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

C#
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
 */

注釈

メソッドは、 GetInterfaces アルファベットまたは宣言の順序など、特定の順序でインターフェイスを返しません。 この順序は変化するため、コードはインターフェイスが返される順序に依存しないようにする必要があります。

現在のが Type 構築ジェネリック型を表している場合、このメソッドは、 Type 適切な型引数によって置き換えられた型パラメーターを持つオブジェクトを返します。

現在のが Type ジェネリック型またはジェネリックメソッドの定義の型パラメーターを表している場合、このメソッドは、インターフェイスの制約と、クラスまたはインターフェイスの制約から継承されたインターフェイスを検索します。

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

こちらもご覧ください