Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 3, 2014 20:51
Show Gist options
  • Save Fhernd/71f4395941287f04f393 to your computer and use it in GitHub Desktop.
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#
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