英語で読む

次の方法で共有


Type.GetInterface メソッド

定義

現在の Type で実装または継承されている特定のインターフェイスを取得します。

オーバーロード

GetInterface(String)

指定した名前のインターフェイスを検索します。

GetInterface(String, Boolean)

派生クラスでオーバーライドされた場合、インターフェイス名の大文字と小文字を区別するかどうかを指定して、指定したインターフェイスを検索します。

GetInterface(String)

ソース:
Type.cs
ソース:
Type.cs
ソース:
Type.cs

指定した名前のインターフェイスを検索します。

C#
public Type? GetInterface (string name);
C#
public Type GetInterface (string name);

パラメーター

name
String

取得するインターフェイスの名前を格納している文字列。 ジェネリック インターフェイスの場合、これは完全修飾名です。

戻り値

現在の Type で実装または継承されているインターフェイスのうち、指定した名前のインターフェイスが存在する場合は、そのインターフェイスを表すオブジェクト。それ以外の場合は null

実装

例外

namenullです。

現在の Type は、別の型の引数と同じジェネリック インターフェイスを実装する型を表します。

次のコード例では、 メソッドをGetInterface(String)使用して インターフェイスの クラスをHashtableIDeserializationCallback検索し、インターフェイスのメソッドを一覧表示します。

このコード例では、 メソッドの GetInterface(String, Boolean) オーバーロードと GetInterfaceMap メソッドも示しています。

C#
public static void Main()
{
    Hashtable hashtableObj = new Hashtable();
    Type objType = hashtableObj.GetType();
    MethodInfo[] arrayMethodInfo;
    MemberInfo[] arrayMemberInfo;
    try
    {
        // Get the methods implemented in 'IDeserializationCallback' interface.
        arrayMethodInfo =objType.GetInterface("IDeserializationCallback").GetMethods();
        Console.WriteLine ("\nMethods of 'IDeserializationCallback' Interface :");
        foreach(MethodInfo methodInfo in arrayMethodInfo)
            Console.WriteLine (methodInfo);

        // Get FullName for interface by using Ignore case search.
        Console.WriteLine ("\nMethods of 'IEnumerable' Interface");
        arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods();
        foreach(MethodInfo methodInfo in arrayMethodInfo)
           Console.WriteLine (methodInfo);

        //Get the Interface methods for 'IDictionary' interface
        InterfaceMapping interfaceMappingOb = objType.GetInterfaceMap(typeof(IDictionary));
        arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
        Console.WriteLine ("\nHashtable class Implements the following IDictionary Interface methods :");
        foreach(MemberInfo memberInfo in arrayMemberInfo)
           Console.WriteLine (memberInfo);
    }
    catch (Exception e)
    {
        Console.WriteLine ("Exception : " + e.ToString());
    }
}

注釈

name 検索では、大文字と小文字が区別されます。

現在 Type の が構築されたジェネリック型を表す場合、このメソッドは、 を適切な型引数に置き換えられた型パラメーターで返 Type します。

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

注意

ジェネリック インターフェイスの name 場合、パラメーターはマングルされた名前で、末尾はグレーブ アクセント (') と型パラメーターの数です。 これは、ジェネリック インターフェイス定義と構築されたジェネリック インターフェイスの両方に当てはまります。 たとえば、 (IExample(Of T)Visual Basic の場合) または IExample<string> ( (IExample(Of String)Visual Basic の場合) を検索IExample<T>するには、 を検索します"IExample`1"

こちらもご覧ください

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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, 4.8.1
.NET Standard 2.0, 2.1

GetInterface(String, Boolean)

ソース:
Type.cs
ソース:
Type.cs
ソース:
Type.cs

派生クラスでオーバーライドされた場合、インターフェイス名の大文字と小文字を区別するかどうかを指定して、指定したインターフェイスを検索します。

C#
public abstract Type? GetInterface (string name, bool ignoreCase);
C#
public abstract Type GetInterface (string name, bool ignoreCase);

パラメーター

name
String

取得するインターフェイスの名前を格納している文字列。 ジェネリック インターフェイスの場合、これは完全修飾名です。

ignoreCase
Boolean

単純なインターフェイス名を指定する true の部分 (名前空間が大文字と小文字を厳密に区別することを指定されている部分) で大文字と小文字の区別を無視する場合は、name

または

false のすべての部分の検索時に大文字と小文字を区別する場合は、name

戻り値

現在の Type で実装または継承されているインターフェイスのうち、指定した名前のインターフェイスが存在する場合は、そのインターフェイスを表すオブジェクト。それ以外の場合は null

実装

例外

namenullです。

現在の Type は、別の型の引数と同じジェネリック インターフェイスを実装する型を表します。

次のコード例では、 メソッドを GetInterface(String, Boolean) 使用して、 インターフェイスの クラスの大文字と小文字を Hashtable 区別しない検索を IEnumerable 実行します。

このコード例では、 メソッドの GetInterface(String) オーバーロードと GetInterfaceMap メソッドも示しています。

C#
public static void Main()
{
    Hashtable hashtableObj = new Hashtable();
    Type objType = hashtableObj.GetType();
    MethodInfo[] arrayMethodInfo;
    MemberInfo[] arrayMemberInfo;
    try
    {
        // Get the methods implemented in 'IDeserializationCallback' interface.
        arrayMethodInfo =objType.GetInterface("IDeserializationCallback").GetMethods();
        Console.WriteLine ("\nMethods of 'IDeserializationCallback' Interface :");
        foreach(MethodInfo methodInfo in arrayMethodInfo)
            Console.WriteLine (methodInfo);

        // Get FullName for interface by using Ignore case search.
        Console.WriteLine ("\nMethods of 'IEnumerable' Interface");
        arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods();
        foreach(MethodInfo methodInfo in arrayMethodInfo)
           Console.WriteLine (methodInfo);

        //Get the Interface methods for 'IDictionary' interface
        InterfaceMapping interfaceMappingOb = objType.GetInterfaceMap(typeof(IDictionary));
        arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
        Console.WriteLine ("\nHashtable class Implements the following IDictionary Interface methods :");
        foreach(MemberInfo memberInfo in arrayMemberInfo)
           Console.WriteLine (memberInfo);
    }
    catch (Exception e)
    {
        Console.WriteLine ("Exception : " + e.ToString());
    }
}

注釈

パラメーターは ignoreCase 、名前空間ではなく、単純なインターフェイス名にのみ適用されます。 名前空間を指定する の name 部分は、大文字と小文字が正しいか、インターフェイスが見つからない必要があります。 たとえば、文字列 "System.icomparable" は インターフェイスを IComparable 検索しますが、文字列 "system.icomparable" は見つかりません。

現在 Type の が構築されたジェネリック型を表す場合、このメソッドは、 を適切な型引数に置き換えられた型パラメーターで返 Type します。

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

注意

ジェネリック インターフェイスの name 場合、パラメーターはマングルされた名前で、末尾はグレーブ アクセント (') と型パラメーターの数です。 これは、ジェネリック インターフェイス定義と構築されたジェネリック インターフェイスの両方に当てはまります。 たとえば、 (IExample(Of T)Visual Basic の場合) または IExample<string> ( (IExample(Of String)Visual Basic の場合) を検索IExample<T>するには、 を検索します"IExample`1"

こちらもご覧ください

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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, 4.8.1
.NET Standard 2.0, 2.1