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 ( "\n Cantidad de tipos anidados en `ClaseExterior`: {0}" , tiposAnidados.Length ) ;
foreach ( Type t in tiposAnidados)
{
Console.WriteLine ( "\n Tipo anidado: {0}\n " , t.ToString ( ) ) ;
}
}
catch( Exception e)
{
Console.WriteLine ( "Error: {0}" , e.Message ) ;
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uUmVmbGVjdGlvbjsKCm5hbWVzcGFjZSBSZWNldGFzLkNhcDAzCnsKICAgIGludGVybmFsIGNsYXNzIENsYXNlRXh0ZXJpb3IKICAgIHsKICAgICAgICBwdWJsaWMgY2xhc3MgQ2xhc2VBbmlkYWRhIHsgfQogICAgICAgIAogICAgICAgIHB1YmxpYyBzdHJ1Y3QgRXN0cnVjdHVyYUFuaWRhZGEgeyB9CiAgICB9CiAgICAKICAgIHB1YmxpYyBjbGFzcyBVc29HZXROZXN0ZWRUeXBlcwogICAgewogICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgICAgICB7CiAgICAgICAgICAgIHRyeQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAvLyBPYnRlbmVtb3MgZWwgdGlwbyBhc29jaWFkbyBhIGxhIGNsYXNlIGBDbGFzZUV4dGVyaW9yYDoKICAgICAgICAgICAgICAgIFR5cGUgdGlwbyA9IHR5cGVvZihDbGFzZUV4dGVyaW9yKTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgLy8gT2J0ZW5lbW9zIGxhIGxpc3RhIGRlIGxvcyB0aXBvcyBhbmlkYWRvcyBlbiBgQ2xhc2VFeHRlcmlvcmA6CiAgICAgICAgICAgICAgICBUeXBlW10gdGlwb3NBbmlkYWRvcyA9IHRpcG8uR2V0TmVzdGVkVHlwZXMoKTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIlxuQ2FudGlkYWQgZGUgdGlwb3MgYW5pZGFkb3MgZW4gYENsYXNlRXh0ZXJpb3JgOiB7MH0iLCB0aXBvc0FuaWRhZG9zLkxlbmd0aCk7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIGZvcmVhY2ggKFR5cGUgdCBpbiB0aXBvc0FuaWRhZG9zKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCJcblRpcG8gYW5pZGFkbzogezB9XG4iLCB0LlRvU3RyaW5nKCkpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGNhdGNoKEV4Y2VwdGlvbiBlKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgiRXJyb3I6IHswfSIsIGUuTWVzc2FnZSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0=