Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Reflection;
  3.  
  4. namespace Recetas.Cap03
  5. {
  6.     internal class ClaseExterior
  7.     {
  8.         public class ClaseAnidada { }
  9.        
  10.         public struct EstructuraAnidada { }
  11.     }
  12.    
  13.     public class UsoGetNestedTypes
  14.     {
  15.         public static void Main()
  16.         {
  17.             try
  18.             {
  19.                 // Obtenemos el tipo asociado a la clase `ClaseExterior`:
  20.                 Type tipo = typeof(ClaseExterior);
  21.                
  22.                 // Obtenemos la lista de los tipos anidados en `ClaseExterior`:
  23.                 Type[] tiposAnidados = tipo.GetNestedTypes();
  24.                
  25.                 Console.WriteLine("\nCantidad de tipos anidados en `ClaseExterior`: {0}", tiposAnidados.Length);
  26.                
  27.                 foreach (Type t in tiposAnidados)
  28.                 {
  29.                     Console.WriteLine("\nTipo anidado: {0}\n", t.ToString());
  30.                 }
  31.             }
  32.             catch(Exception e)
  33.             {
  34.                 Console.WriteLine("Error: {0}", e.Message);
  35.             }
  36.         }
  37.     }
  38. }