다음을 통해 공유


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 현재가 직접 상속 null 하거나 현재 Type 가 클래스 또는 인터페이스를 Object 나타내는 경우 Type 입니다.

구현

예제

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

using System;
class TestType
{
    public static void Main()
    {
        Type t = typeof(int);
        Console.WriteLine("{0} inherits from {1}.", t,t.BaseType);
    }
}
let t = typeof<int>
printfn $"{t} inherits from {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

다음 예제에서는 재귀를 사용하여 어셈블리에 있는 각 클래스의 전체 상속 계층 구조를 나열합니다. 이 예제에서는 이름이 지정된 B클래스에서 파생되는 클래스 C 를 정의합니다. 이 클래스는 다시 명명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
type A() = class end 

type B() = inherit A()

type C() = inherit B()   

module Example =
    [<EntryPoint>]
    let main _ =
        for t in typeof<A>.Assembly.GetTypes() do
            printfn $"{t.FullName} derived from: "
            let mutable derived = t
            while derived <> null do
                derived <- derived.BaseType
                if derived <> null then 
                    printfn $"   {derived.FullName}"
            printfn ""
        0
// 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개 이상의 기본 인터페이스에서 상속됩니다. 따라서 개체가 인터페이스를 Type 나타내는 경우 이 속성이 반환 null 됩니다. 기본 인터페이스는 다음으로 또는 FindInterfaces.로 GetInterfaces 확인할 수 있습니다.

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

class B<U> { }
class C<T> : B<T> { }
type B<'U>() = class end
type C<'T>() = inherit 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.

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

적용 대상

추가 정보