Share via


Type.GetInterfaces メソッド

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

Public MustOverride Function GetInterfaces() As Type()
[C#]
public abstract Type[] GetInterfaces();
[C++]
public: virtual Type* GetInterfaces() [] = 0;
[JScript]
public abstract function GetInterfaces() : Type[];

戻り値

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

または

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

例外

例外の種類 条件
TargetInvocationException 静的初期化子が呼び出され、例外をスローします。

使用例

[Visual Basic, C#, C++] 指定したクラスの型を取得し、その型が実装または継承しているすべてのインターフェイスを表示する例を示します。Visual Basic の例をコンパイルするには、次のコンパイラ コマンドを使用します。

[Visual Basic, C#, C++] vbc type_getinterfaces1.vb /r:System.Web.dll /r:System.dll

 

Imports System
Imports System.Web
Imports System.Web.UI
Imports Microsoft.VisualBasic

Namespace Samples
    Public Class MyTemplate
        Inherits Control
        Implements INamingContainer
        Private _message As [String] = Nothing
        Public Property Message() As [String]
            Get
                Return _message
            End Get
            Set(ByVal Value As [String])
                _message = value
            End Set
        End Property
    End Class
    Public Class MyInterfacesSample
        Public Shared Sub Main()
            Try
                Dim myObjectArray As Type() = GetType(MyTemplate).GetInterfaces()
                Console.WriteLine("The interfaces inherited by the MyTemplate class are:" + ControlChars.CrLf)
                Dim index As Integer
                For index = 0 To myObjectArray.Length - 1
                    Console.WriteLine(myObjectArray(index))
                Next index
            Catch e As Exception
                Console.WriteLine("An exception occurred.")
                Console.WriteLine("Message: {0}", e.Message)
            End Try
        End Sub
    End Class
End Namespace

[C#] 

using System;
using System.Web;
using System.Web.UI;

namespace Samples
{
    public class MyTemplate : Control, INamingContainer 
    {
        private String _message = null;
        public String Message 
        {
            get 
            {
                return _message;
            }
            set 
            {
                _message = value;
            }
        }    
    }
    public class MyInterfacesSample
    {
        public static void Main()
        {
            try
            {
                Type[] myObjectArray= typeof(MyTemplate).GetInterfaces();
                Console.WriteLine("The interfaces inherited by the MyTemplate class are:\n");
                for (int index = 0; index < myObjectArray.Length; index++)
                {    
                    Console.WriteLine(myObjectArray[index]);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception occurred.");
                Console.WriteLine("Message: " + e.Message);
            }
        }
    }
}

[C++] 

#using <mscorlib.dll>
#using <system.dll>
#using <system.web.dll>

using namespace System;
using namespace System::Web;
using namespace System::Web::UI;

public __gc class MyTemplate : public Control, public INamingContainer
{
private:
   String* _message;
public:
   __property String* get_Message() {

      return _message;

   }
   __property void set_Message(String* value) {

      _message = value;

   }
};

int main() {
   try {
      Type* myObjectArray[]= __typeof(MyTemplate)->GetInterfaces();
      Console::WriteLine(S"The interfaces inherited by the MyTemplate class are:\n");
      for (int index = 0; index < myObjectArray->Length; index++) {
         Console::WriteLine(myObjectArray->Item[index]);
      }
   } catch (Exception* e) {
      Console::WriteLine(S"An exception occurred.");
      Console::WriteLine(S"Message: {0}", e->Message);
   }
}

[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 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

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