Type.IsAbstract 속성

정의

Type이 추상이며 재정의되어야 하는지 여부를 나타내는 값을 가져옵니다.

public:
 property bool IsAbstract { bool get(); };
public bool IsAbstract { get; }
member this.IsAbstract : bool
Public ReadOnly Property IsAbstract As Boolean

속성 값

Type이 추상이면 true이고, 그렇지 않으면 false입니다.

구현

예제

다음 예제에서는 다음 형식을 나타내는 개체의 Type 배열을 만듭니다. 지정된 개체abstract가 이면 type returns true 를 포함하고, 그렇지 않으면 를 반환합니다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.

적용 대상

추가 정보