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が抽象である場合は (a0/>。それ以外の場合はfalse。
実装
例
次の例では、次の型を表すType オブジェクトの配列を作成します。指定したオブジェクトがabstract場合はtrueを返します。それ以外の場合は、falseを返します。
AbstractClass抽象クラス (C# ではabstract、Visual Basic ではMustInheritとしてマークされたクラス)。DerivedClassは、AbstractClassから継承するクラスです。SingleClassは継承できないクラスです。 C# ではsealedとして定義され、Visual Basic ではNotInheritable。ITypeInfo、インターフェイス。ImplementingClassは、ITypeInfoインターフェイスを実装するクラスです。
このメソッドは、インターフェイスのAbstractClass、抽象クラス、およびITypeInfoに対してのみ、trueを返します。
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
[<AbstractClass>]
type AbstractClass() = class end
type DerivedClass() = inherit AbstractClass()
[<Sealed>]
type SingleClass() = class end
type ITypeInfo =
abstract GetName: unit -> string
type ImplementingClass() =
interface ITypeInfo with
member this.GetName() =
this.GetType().FullName
type DiscriminatedUnion =
| Yes
| No of string
type Record =
{ Name: string
Age: int }
type InputOutput = delegate of inp: string -> string
let types =
[ typeof<AbstractClass>
typeof<DerivedClass>
typeof<ITypeInfo>
typeof<SingleClass>
typeof<ImplementingClass>
typeof<DiscriminatedUnion>
typeof<Record>
typeof<InputOutput> ]
for typ in types do
printfn $"{typ.Name} is abstract: {typ.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
// DiscriminatedUnion is abstract: True
// Record 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を返します。
現在の型は抽象型です。つまり、インスタンス化することはできませんが、派生クラスの基底クラスとしてのみ機能できます。 C# では、抽象クラスは abstract キーワードでマークされます。F# では、 AbstractClass 属性でマークされます。Visual Basic では、 MustInherit キーワードでマークされます。
現在の型はインターフェイスです。
現在の Type がジェネリック型またはジェネリック メソッドの定義で型パラメーターを表す場合、このプロパティは常に falseを返します。