次の方法で共有


Type.IsAbstract プロパティ

Type が抽象型で、オーバーライドする必要があるかどうかを示す値を取得します。

Public ReadOnly Property IsAbstract As Boolean
[C#]
public bool IsAbstract {get;}
[C++]
public: __property bool get_IsAbstract();
[JScript]
public function get IsAbstract() : Boolean;

プロパティ値

Type が抽象である場合は true 。それ以外の場合は false

使用例

[Visual Basic, C#, C++] 指定したオブジェクトが abstract (Visual Basic では MustOverride) の場合は true 、それ以外の場合は false を返す例を次に示します。

 
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public MustInherit Class MyMustInheritClass
End Class 'MyMustInheritClass
Public Class [MyClass]
End Class '[MyClass]
Public Class Type_IsMustInherit
    Public Shared Sub Main()
        Try
            ' Check whether the return type of MyMustInheritClass is MustInherit or not.
            Console.WriteLine(ControlChars.NewLine + "Checking whether the type is MustInherit." + ControlChars.NewLine)

            If GetType([MyMustInheritClass]).IsAbstract = True Then
                Console.WriteLine("MyMustInheritClass is {0}", "a MustInherit class.")
            Else
                Console.WriteLine("MyMustInheritClass is {0}", "not a MustInherit class.")
            End If
            ' Check whether the return type of MyClass is MustInherit or not.
            If GetType([MyClass]).IsAbstract = True Then
                Console.WriteLine("MyClass is {0}", "a MustInherit class.")
            Else
                Console.WriteLine("MyClass is {0}", "not a MustInherit class.")
            End If
        Catch e As Exception
            Console.WriteLine("Exception: {0} " + ControlChars.Cr, e.Message.ToString())
        End Try
    End Sub 'Main
End Class 'Type_IsMustInherit

[C#] 

using System;
using System.Reflection;
public abstract class MyAbstractClass 
{
}
public class MyClass
{
}
public class Type_IsAbstract
{
    public static void Main()
    {
        try
        {
            // Check whether the return type of MyAbstractClass is abstract or not.
            Console.WriteLine("\nChecking whether the type is abstract.\n"); 
            Console.WriteLine("MyAbstractClass is {0}", (typeof(MyAbstractClass).IsAbstract) ? "an abstract class." : "not an abstract class.");
            // Check whether the return type of MyClass is abstract or not.
            Console.WriteLine("MyClass is {0}", (typeof(MyClass).IsAbstract) ? "an abstract class." : "not an abstract class.");
        }
        catch( Exception e )
        {
            Console.WriteLine( "Exception: {0} \n", e.Message ); 
        }
    }
}

[C++] 

#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;
public __gc class MyAbstractClass {
   virtual f() = 0; // pure virtual function makes this class abstract.
};
public __gc class MyClass {
};
int main() {
   try {
      // Check whether the return type of MyAbstractClass is abstract or not.
      Console::WriteLine(S"\nChecking whether the type is abstract.\n");
      Console::WriteLine(S"MyAbstractClass is {0}", (__typeof(MyAbstractClass)->IsAbstract) ? S"an abstract class." : S"not an abstract class.");
      // Check whether the return type of MyClass is abstract or not.
      Console::WriteLine(S"MyClass is {0}", (__typeof(MyClass)->IsAbstract) ? S"an abstract class." : S"not an abstract class.");
   } catch (Exception* e) {
      Console::WriteLine(S"Exception: {0} \n", 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 名前空間 | TypeAttributes