次の方法で共有


Type.GetInterface メソッド (String)

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

Overloads Public Function GetInterface( _
   ByVal name As String _) As Type
[C#]
public Type GetInterface(stringname);
[C++]
public: Type* GetInterface(String* name);
[JScript]
public function GetInterface(
   name : String) : Type;

パラメータ

  • name
    取得するインターフェイスの名前を格納している String

戻り値

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

例外

例外の種類 条件
ArgumentNullException name が null 参照 (Visual Basic では Nothing) です。

解説

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

使用例

 
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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard

参照

Type クラス | Type メンバ | System 名前空間 | Type.GetInterface オーバーロードの一覧 | String | GetInterfaces | FindInterfaces