Type.BaseType Özellik

Tanım

Geçerlinin doğrudan devralınan Type türü alır.

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

Özellik Değeri

Type

Geçerlinin Type doğrudan Type devralınma durumu veya null geçerlinin sınıfı veya Type arabirimi temsil Object ettiği.

Uygulamalar

Örnekler

Aşağıdaki örnekte özelliğinin kullanımı BaseType göstermektedir.

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

Aşağıdaki örnek, bir derlemede bulunan her sınıfın tam devralma hiyerarşisini listeleyen bir recursion kullanır. Örnek, adlı bir sınıftan türeten adlı bir sınıf tanımlar ve bu da C B adlı bir sınıftan türetir. 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

Açıklamalar

Temel tür, geçerli türün doğrudan devralınma türüdir. Object , temel türüne sahip tek tür değildir, bu null nedenle temel türü olarak Object döndürülür.

Arabirimler sıfır veya daha fazla temel arabirimden devralır; bu nedenle, nesne bir null arabirimi temsil Type ediyorsa bu özellik döndürür. Temel arabirimler veya ile GetInterfaces FindInterfaces belirlenebilirsiniz.

Geçerli, Type oluşturulmuş bir genel türü temsil ediyorsa, temel tür genel bağımsız değişkenleri gösterir. Örneğin, aşağıdaki bildirimleri göz önünde bulundurarak:

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

Özelliği, oluşturulmuş C<int> türü ( C(Of Integer) Visual Basic) BaseType B<int> döndürür.

Geçerli genel tür tanımının bir tür parametresini temsil ediyorsa, sınıf kısıtlamasını döndürür, yani tür Type BaseType parametresinin devralması gereken sınıf. Sınıf kısıtlaması yoksa BaseType System.Object döndürür.

Bu özellik salt okunur durumdadır.

Şunlara uygulanır

Ayrıca bkz.