Created
June 3, 2014 20:51
-
-
Save Fhernd/71f4395941287f04f393 to your computer and use it in GitHub Desktop.
Demostración del método GetNestedTypes de la clase System.Type en C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
namespace Recetas.Cap03 | |
{ | |
internal class ClaseExterior | |
{ | |
public class ClaseAnidada { } | |
public struct EstructuraAnidada { } | |
} | |
public class UsoGetNestedTypes | |
{ | |
public static void Main() | |
{ | |
try | |
{ | |
// Obtenemos el tipo asociado a la clase `ClaseExterior`: | |
Type tipo = typeof(ClaseExterior); | |
// Obtenemos la lista de los tipos anidados en `ClaseExterior`: | |
Type[] tiposAnidados = tipo.GetNestedTypes(); | |
Console.WriteLine("\nCantidad de tipos anidados en `ClaseExterior`: {0}", tiposAnidados.Length); | |
foreach (Type t in tiposAnidados) | |
{ | |
Console.WriteLine("\nTipo anidado: {0}\n", t.ToString()); | |
} | |
} | |
catch(Exception e) | |
{ | |
Console.WriteLine("Error: {0}", e.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment