Language

Type.GetInterface メソッド

定義

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

オーバーロード

名前 説明
GetInterface(String)

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

GetInterface(String, Boolean)

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

GetInterface(String)

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

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

public:
 Type ^ GetInterface(System::String ^ name);
public:
 virtual Type ^ GetInterface(System::String ^ name);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.Interfaces)]
public Type? GetInterface(string name);
public Type? GetInterface(string name);
public Type GetInterface(string name);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.Interfaces)>]
member this.GetInterface : string -> Type
member this.GetInterface : string -> Type
abstract member GetInterface : string -> Type
override this.GetInterface : string -> Type
Public Function GetInterface (name As String) As Type

パラメーター

name
String

取得するインターフェイスの名前を含む文字列。 ジェネリック インターフェイスの場合、これはマングル名です。

返品

現在の Typeによって実装または継承された、指定した名前のインターフェイスを表すオブジェクト (見つかった場合)。 それ以外の場合は null。

実装

属性

例外

name は nullです。

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

例

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

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

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());
    }
}
let hashtableObj = Hashtable()
let objType = hashtableObj.GetType()
try
    // Get the methods implemented in 'IDeserializationCallback' interface.
    let arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods()
    printfn "\nMethods of 'IDeserializationCallback' Interface :"
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    // Get FullName for interface by using Ignore case search.
    printfn "\nMethods of 'IEnumerable' Interface"
    let arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods()
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    //Get the Interface methods for 'IDictionary' interface
    let interfaceMappingObj = objType.GetInterfaceMap typeof<IDictionary>
    let arrayMemberInfo = interfaceMappingObj.InterfaceMethods
    printfn "\nHashtable class Implements the following IDictionary Interface methods :"
    for memberInfo in arrayMemberInfo do
        printfn $"{memberInfo}"
with e ->
    printfn $"Exception : {e}"
   Public Shared Sub Main()
      Dim hashtableObj As New Hashtable()
      Dim objType As Type = hashtableObj.GetType()
      Dim arrayMemberInfo() As MemberInfo
      Dim arrayMethodInfo() As MethodInfo
      Try
         ' Get the methods implemented in 'IDeserializationCallback' interface.
         arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods()
         Console.WriteLine(ControlChars.Cr + "Methods of 'IDeserializationCallback' Interface :")
         Dim index As Integer
         For index = 0 To arrayMethodInfo.Length - 1
            Console.WriteLine(arrayMethodInfo(index).ToString())
         Next index
         ' Get FullName for interface by using Ignore case search.
         Console.WriteLine(ControlChars.Cr + "Methods of 'IEnumerable' Interface")
         arrayMethodInfo = objType.GetInterface("ienumerable", True).GetMethods()
         For index = 0 To arrayMethodInfo.Length - 1
            Console.WriteLine(arrayMethodInfo(index).ToString())
         Next index
         'Get the Interface methods for 'IDictionary' interface
         Dim interfaceMappingObj As InterfaceMapping
         interfaceMappingObj = objType.GetInterfaceMap(GetType(IDictionary))
         arrayMemberInfo = interfaceMappingObj.InterfaceMethods
         Console.WriteLine(ControlChars.Cr + "Hashtable class Implements the following IDictionary Interface methods :")
         For index = 0 To arrayMemberInfo.Length - 1
            Console.WriteLine(arrayMemberInfo(index).ToString())
         Next index
      Catch e As Exception
         Console.WriteLine(("Exception : " + e.ToString()))
      End Try
   End Sub
End Class

注釈

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

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

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

Note

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

こちらもご覧ください

適用対象

GetInterface(String, Boolean)

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

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

public:
 abstract Type ^ GetInterface(System::String ^ name, bool ignoreCase);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.Interfaces)]
public abstract Type? GetInterface(string name, bool ignoreCase);
public abstract Type? GetInterface(string name, bool ignoreCase);
public abstract Type GetInterface(string name, bool ignoreCase);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.Interfaces)>]
abstract member GetInterface : string * bool -> Type
abstract member GetInterface : string * bool -> Type
Public MustOverride Function GetInterface (name As String, ignoreCase As Boolean) As Type

パラメーター

name
String

取得するインターフェイスの名前を含む文字列。 ジェネリック インターフェイスの場合、これはマングル名です。

ignoreCase
Boolean

true 単純なインターフェイス名を指定する name のその部分の大文字と小文字が区別されません (名前空間を指定する部分は正しく大文字と小文字を区別する必要があります)。

-又は-

false を使用して、 nameのすべての部分に対して大文字と小文字を区別する検索を実行します。

返品

現在の Typeによって実装または継承された、指定した名前のインターフェイスを表すオブジェクト (見つかった場合)。 それ以外の場合は null。

実装

属性

例外

name は nullです。

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

例

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

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

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());
    }
}
let hashtableObj = Hashtable()
let objType = hashtableObj.GetType()
try
    // Get the methods implemented in 'IDeserializationCallback' interface.
    let arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods()
    printfn "\nMethods of 'IDeserializationCallback' Interface :"
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    // Get FullName for interface by using Ignore case search.
    printfn "\nMethods of 'IEnumerable' Interface"
    let arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods()
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    //Get the Interface methods for 'IDictionary' interface
    let interfaceMappingObj = objType.GetInterfaceMap typeof<IDictionary>
    let arrayMemberInfo = interfaceMappingObj.InterfaceMethods
    printfn "\nHashtable class Implements the following IDictionary Interface methods :"
    for memberInfo in arrayMemberInfo do
        printfn $"{memberInfo}"
with e ->
    printfn $"Exception : {e}"
   Public Shared Sub Main()
      Dim hashtableObj As New Hashtable()
      Dim objType As Type = hashtableObj.GetType()
      Dim arrayMemberInfo() As MemberInfo
      Dim arrayMethodInfo() As MethodInfo
      Try
         ' Get the methods implemented in 'IDeserializationCallback' interface.
         arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods()
         Console.WriteLine(ControlChars.Cr + "Methods of 'IDeserializationCallback' Interface :")
         Dim index As Integer
         For index = 0 To arrayMethodInfo.Length - 1
            Console.WriteLine(arrayMethodInfo(index).ToString())
         Next index
         ' Get FullName for interface by using Ignore case search.
         Console.WriteLine(ControlChars.Cr + "Methods of 'IEnumerable' Interface")
         arrayMethodInfo = objType.GetInterface("ienumerable", True).GetMethods()
         For index = 0 To arrayMethodInfo.Length - 1
            Console.WriteLine(arrayMethodInfo(index).ToString())
         Next index
         'Get the Interface methods for 'IDictionary' interface
         Dim interfaceMappingObj As InterfaceMapping
         interfaceMappingObj = objType.GetInterfaceMap(GetType(IDictionary))
         arrayMemberInfo = interfaceMappingObj.InterfaceMethods
         Console.WriteLine(ControlChars.Cr + "Hashtable class Implements the following IDictionary Interface methods :")
         For index = 0 To arrayMemberInfo.Length - 1
            Console.WriteLine(arrayMemberInfo(index).ToString())
         Next index
      Catch e As Exception
         Console.WriteLine(("Exception : " + e.ToString()))
      End Try
   End Sub
End Class

注釈

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

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

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

Note

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

こちらもご覧ください

適用対象