次の方法で共有


Type.GetInterface メソッド

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

オーバーロードの一覧

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

[Visual Basic] Overloads Public Function GetInterface(String) As Type

[C#] public Type GetInterface(string);

[C++] public: Type* GetInterface(String*);

[JScript] public function GetInterface(String) : Type;

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

[Visual Basic] Overloads Public MustOverride Function GetInterface(String, Boolean) As Type

[C#] public abstract Type GetInterface(string, bool);

[C++] public: virtual Type* GetInterface(String*, bool) = 0;

[JScript] public abstract function GetInterface(String, Boolean) : Type;

使用例

[Visual Basic, C#, C++] メモ   ここでは、GetInterface のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
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 'Main
End Class 'MyInterfaceClass 

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

        // Get FullName for interface by using Ignore case search.
        Console.WriteLine ("\nMethods of 'IEnumerable' Interface");
        arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods();
        for(int index=0;index < arrayMethodInfo.Length ;index++)
           Console.WriteLine (arrayMethodInfo[index].ToString()); 
       
        //Get the Interface methods for 'IDictionary' interface
        InterfaceMapping interfaceMappingObj;
        interfaceMappingObj = objType.GetInterfaceMap(typeof(IDictionary));
        arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
        Console.WriteLine ("\nHashtable class Implements the following IDictionary Interface methods :");
        for(int index=0; index < arrayMemberInfo.Length; index++)
            Console.WriteLine (arrayMemberInfo[index].ToString() ); 
    }
    catch (Exception e)
    {
        Console.WriteLine ("Exception : " + e.ToString());            
    }                 
}

[C++] 
int main() {
   Hashtable* hashtableObj = new Hashtable();
   Type*  objType = hashtableObj->GetType();
   MemberInfo* arrayMemberInfo[];
   MethodInfo* arrayMethodInfo[];
   try {
      // Get the methods implemented in 'IDeserializationCallback' interface.
      arrayMethodInfo =objType->GetInterface(S"IDeserializationCallback")->GetMethods();
      Console::WriteLine (S"\nMethods of 'IDeserializationCallback' Interface :");
      for (int index=0;index < arrayMethodInfo->Length ;index++)
         Console::WriteLine (arrayMethodInfo->Item[index]);

      // Get FullName for interface by using Ignore case search.
      Console::WriteLine (S"\nMethods of 'IEnumerable' Interface");
      arrayMethodInfo = objType->GetInterface(S"ienumerable", true)->GetMethods();
      for (int index=0;index < arrayMethodInfo->Length ;index++)
         Console::WriteLine (arrayMethodInfo->Item[index]);

      //Get the Interface methods for 'IDictionary*' interface
      InterfaceMapping interfaceMappingObj;
      interfaceMappingObj = objType->GetInterfaceMap(__typeof(IDictionary));
      arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
      Console::WriteLine (S"\nHashtable class Implements the following IDictionary Interface methods :");
      for (int index=0; index < arrayMemberInfo->Length; index++)
         Console::WriteLine (arrayMemberInfo->Item[index]);
   } catch (Exception* e) {
      Console::WriteLine (S"Exception : {0}", e);
   }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

Type クラス | Type メンバ | System 名前空間