Mega Code Archive

 
Categories / C# Book / 09 Reflection
 

0613 Obtaining nested types

To retrieve nested types, call GetNestedTypes on the containing type. For example: using System; using System.Reflection; using System.Collections.Generic; class MainClass { static void Main() { foreach (Type t in typeof(System.Environment).GetNestedTypes()) Console.WriteLine(t.FullName); } } The output: System.Environment+SpecialFolderOption System.Environment+SpecialFolder using System; using System.Reflection; using System.Collections.Generic; class MainClass { static void Main() { Type t = typeof(System.Environment.SpecialFolder); Console.WriteLine(t.IsPublic); // False Console.WriteLine(t.IsNestedPublic); // True } } The output: False True