Type.IsAbstract プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
Type が抽象型で、オーバーライドする必要があるかどうかを示す値を取得します。
public:
property bool IsAbstract { bool get(); };
public bool IsAbstract { get; }
member this.IsAbstract : bool
Public ReadOnly Property IsAbstract As Boolean
プロパティ値
true
が抽象である場合は Type。それ以外の場合は false
。
実装
例
次の例では、次の型を表す オブジェクトの配列を作成します。指定したオブジェクトが の場合、contains 型は を返します。それ以外の場合は を Type true
abstract
返します false
。
AbstractClass
: 抽象クラス (C# では としてマークされ、クラスabstract
はMustInherit
Visual Basic)。DerivedClass
。 から継承するクラスAbstractClass
。SingleClass
:継承できないクラス。 これはsealed
、C# では として定義され、NotInheritable
では Visual Basic。ITypeInfo
インターフェイスです。ImplementingClass
インターフェイスを実装するITypeInfo
クラス。
メソッドは、、 true
抽象クラス AbstractClass
、および インターフェイスに対 ITypeInfo
してのみを返します。
using System;
public abstract class AbstractClass
{}
public class DerivedClass : AbstractClass
{}
public sealed class SingleClass
{}
public interface ITypeInfo
{
string GetName();
}
public class ImplementingClass : ITypeInfo
{
public string GetName()
{
return this.GetType().FullName;
}
}
delegate string InputOutput(string inp);
public class Example
{
public static void Main()
{
Type[] types= { typeof(AbstractClass),
typeof(DerivedClass),
typeof(ITypeInfo),
typeof(SingleClass),
typeof(ImplementingClass),
typeof(InputOutput) };
foreach (var type in types)
Console.WriteLine("{0} is abstract: {1}",
type.Name, type.IsAbstract);
}
}
// The example displays the following output:
// AbstractClass is abstract: True
// DerivedClass is abstract: False
// ITypeInfo is abstract: True
// SingleClass is abstract: False
// ImplementingClass is abstract: False
// InputOutput is abstract: False
Public MustInherit Class AbstractClass
End Class
Public Class DerivedClass : Inherits AbstractClass
End Class
Public NotInheritable Class SingleClass
End Class
Public Interface ITypeInfo
Function GetName() As String
End Interface
Public Class ImplementingClass : Implements ITypeInfo
Public Function GetName() As String _
Implements ITypeInfo.GetName
Return Me.GetType().FullName
End Function
End Class
Delegate Function InputOutput(inp As String) As String
Module Example
Public Sub Main()
Dim types() As Type = { GetType(AbstractClass),
GetType(DerivedClass),
GetType(ITypeInfo),
GetType(SingleClass),
GetType(ImplementingClass),
GetType(InputOutput) }
For Each type In types
Console.WriteLine("{0} is abstract: {1}",
type.Name, type.IsAbstract)
Next
End Sub
End Module
' The example displays the following output:
' AbstractClass is abstract: True
' DerivedClass is abstract: False
' ITypeInfo is abstract: True
' SingleClass is abstract: False
' ImplementingClass is abstract: False
' InputOutput is abstract: False
注釈
プロパティ IsAbstract は、次 true
の場合に を返します。
現在の型は abstract です。つまり、インスタンス化することはできませんが、派生クラスの基本クラスとしてのみ使用できます。 C# では、抽象クラスは abstract キーワードでマークされます。ではVisual Basic MustInherit キーワードでマークされます。
現在の型はインターフェイスです。
現在の がジェネリック型またはジェネリック メソッドの定義で型パラメーターを表している場合、このプロパティは常に Type を返します false
。