Christopher Ireland said:
I'm trying to find an example of a nested class implemented within the .NET
Framework itself but without much success. I don't suppose that anybody
knows of such an example off the top of their head, do they?
Well, the following shows all the *public* nested types within
mscorlib.dll:
using System;
using System.Reflection;
class Test
{
static void Main()
{
Assembly mscorlib = typeof(string).Assembly;
Type[] types = mscorlib.GetTypes();
foreach (Type t in types)
{
if (t.IsNestedPublic)
{
Console.WriteLine(t);
}
}
}
}
This only yields
System.Environment+SpecialFolder
System.Runtime.InteropServices.ELEMDESC+DESCUNION
System.Runtime.InteropServices.VARDESC+DESCUNION
There may be others in System.dll etc. In particular, there are loads
in System.Windows.Forms.dll - although many of those don't have public
enclosing type (which makes the nested type being public pretty
pointless, I think).
To see *all* nested types in an assembly (including automatically
generated ones) change the test to
if (t.DeclaringType != null)