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
。
次の例では、次の型を表す オブジェクトの Type 配列を作成します。指定したオブジェクトが の場合は contains 型が返 true
されます。それ以外の場合は abstract
を返します false
。
AbstractClass
、抽象クラス (C# およびMustInherit
Visual Basic で としてabstract
マークされたクラス)。DerivedClass
からAbstractClass
継承するクラス。SingleClass
、継承不可能なクラス。 これは、C# とNotInheritable
Visual Basic で とsealed
定義されています。ITypeInfo
、インターフェイス。ImplementingClass
インターフェイスを実装するITypeInfo
クラス。
メソッドは、 、抽象クラス、および ITypeInfo
インターフェイスに対AbstractClass
してのみ を返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# では、抽象クラスは抽象キーワード (keyword)でマークされます。F# では、AbstractClass 属性でマークされます。Visual Basic では、MustInherit キーワード (keyword)でマークされます。
現在の型は インターフェイスです。
現在 Type の がジェネリック型またはジェネリック メソッドの定義で型パラメーターを表す場合、このプロパティは常に を返します false
。
製品 | バージョン |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。