Type.BaseType 속성

정의

현재 Type이 직접 상속된 형식을 가져옵니다.

public:
 abstract property Type ^ BaseType { Type ^ get(); };
public abstract Type? BaseType { get; }
public abstract Type BaseType { get; }
member this.BaseType : Type
Public MustOverride ReadOnly Property BaseType As Type

속성 값

Type

현재 Type이 직접 상속하는 Type이거나, 현재 nullType 클래스나 인터페이스를 나타내면 Object입니다.

구현

예제

다음 예제에서는 속성을 사용 하는 방법을 보여 줍니다 BaseType .

using namespace System;
void main()
{
   Type^ t = int::typeid;
   Console::WriteLine( "{0} inherits from {1}.", t, t->BaseType );
}
using System;
class TestType
{
    public static void Main()
    {
        Type t = typeof(int);
        Console.WriteLine("{0} inherits from {1}.", t,t.BaseType);
    }
}
Class TestType
   
    Public Shared Sub Main()
        Dim t As Type = GetType(Integer)
        Console.WriteLine("{0} inherits from {1}.", t, t.BaseType)
    End Sub
End Class

다음 예제에서는 재귀를 사용 하 여 어셈블리에 있는 각 클래스의 완전 한 상속 계층을 나열 합니다. 이 예제에서는 라는 클래스에서 파생 되는 이라는 클래스를 정의 합니다 .이 클래스는 이라는 클래스 C B 에서 파생 A 됩니다.

using System;

public class Example
{
   public static void Main()
   {
      foreach (var t in typeof(Example).Assembly.GetTypes()) {
         Console.WriteLine("{0} derived from: ", t.FullName);
         var derived = t;
         do { 
            derived = derived.BaseType;
            if (derived != null) 
               Console.WriteLine("   {0}", derived.FullName);
         } while (derived != null);
         Console.WriteLine(); 
      } 
   }
}

public class A {} 

public class B : A
{}

public class C : B   
{}
// The example displays the following output:
//       Example derived from:
//          System.Object
//       
//       A derived from:
//          System.Object
//       
//       B derived from:
//          A
//          System.Object
//       
//       C derived from:
//          B
//          A
//          System.Object
Public Class Example
   Public Shared Sub Main()
      For Each t In GetType(Example).Assembly.GetTypes()
         Console.WriteLine("{0} derived from: ", t.FullName)
         Dim derived As Type = t
         Do 
            derived = derived.BaseType
            If derived IsNot Nothing Then 
               Console.WriteLine("   {0}", derived.FullName)
            End If   
         Loop While derived IsNot Nothing
         Console.WriteLine() 
      Next 
   End Sub
End Class

Public Class A 
End Class

Public Class B : Inherits A
End Class

Public Class C : Inherits B
End Class
' The example displays the following output:
'       Example derived from:
'          System.Object
'       
'       A derived from:
'          System.Object
'       
'       B derived from:
'          A
'          System.Object
'       
'       C derived from:
'          B
'          A
'          System.Object

설명

기본 형식은 현재 형식이 직접 상속 하는 형식입니다. Object 는 기본 형식이 없는 유일한 형식 이므로 null 의 기본 형식으로 반환 됩니다 Object .

인터페이스는 0 개 이상의 기본 인터페이스에서 상속 됩니다. 따라서 null 개체가 인터페이스를 나타내는 경우이 속성은를 반환 합니다 Type . 기본 인터페이스는 또는을 사용 하 여 확인할 수 있습니다 GetInterfaces FindInterfaces .

현재이 Type 생성 된 제네릭 형식을 나타내는 경우 기본 형식은 제네릭 인수를 반영 합니다. 예를 들어 다음 선언을 살펴보세요.

generic<typename U> ref class B { };
generic<typename T> ref class C : B<T> { };
class B<U> { }
class C<T> : B<T> { }
Class B(Of U)
End Class
Class C(Of T)
    Inherits B(Of T)
End Class

생성 된 형식 C<int> ( C(Of Integer) Visual Basic)의 경우 속성은를 반환 합니다 BaseType B<int> .

현재 Type 이 제네릭 형식 정의의 형식 매개 변수를 나타내는 경우 BaseType 클래스 제약 조건 즉, 형식 매개 변수에서 상속 해야 하는 클래스를 반환 합니다. 클래스 제약 조건이 없는 경우는를 BaseType 반환 System.Object 합니다.

이 속성은 읽기 전용입니다.

적용 대상

추가 정보