Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Propiedad Type.BaseType

 

Publicado: octubre de 2016

Obtiene el tipo del que hereda directamente el objeto Type actual.

Espacio de nombres:   System
Ensamblado:  mscorlib (en mscorlib.dll)

public abstract Type BaseType { get; }

Valor de propiedad

Type: System.Type

Type desde el cual el objeto Type actual hereda directamente, o null si el objeto Type actual representa la clase Object o una interfaz.

Implementa

_Type.BaseType

The base type is the type from which the current type directly inherits. T:System.Object is the only type that does not have a base type, therefore null is returned as the base type of T:System.Object.

Interfaces inherit from zero or more base interfaces; therefore, this property returns null if the Type object represents an interface. The base interfaces can be determined with M:System.Type.GetInterfaces or M:System.Type.FindInterfaces(System.Reflection.TypeFilter,System.Object).

If the current T:System.Type represents a constructed generic type, the base type reflects the generic arguments. For example, consider the following declarations:

class B<U> { }
class C<T> : B<T> { }

For the constructed type C<int> (C(Of Integer) in Visual Basic), the P:System.Type.BaseType property returns B<int>.

If the current T:System.Type represents a type parameter of a generic type definition, P:System.Type.BaseType returns the class constraint, that is, the class the type parameter must inherit. If there is no class constraint, P:System.Type.BaseType returns T:System.Object.

This property is read-only.

The following example demonstrates using the P:System.Type.BaseType property.

using System;
class TestType 
{
    public static void Main() 
    {
        Type t = typeof(int);
        Console.WriteLine("{0} inherits from {1}.", t,t.BaseType);
    }
}

The following example uses recursion to list the complete inheritance hierarchy of each class found in an assembly. The example defines a class named C that derives from a class named B, which, in turn, derives from a class named 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

.NET Framework
Disponible desde 1.1
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0
Volver al principio
Mostrar: