Use GetNestedTypes() instead with the correct BindingFlags for public constants:
var nestedTypes = typeof(MainFoo).GetNestedTypes(BindingFlags.Public);
foreach (Type type in nestedTypes)
{
FieldInfo[] constants = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
// <do stuff here>
}
CLICK HERE to find out more related problems solutions.