How to enumerate all Enums in a Class

  • Thread starter Thread starter Faisal
  • Start date Start date
F

Faisal

Can anyone tell me if it is possible to enumerate through all the Enums within a class [and not the individual enumerations within a single Enum]. I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't seem to find an appropriate Reflection method to access Enums within a class

I would like to loop through the Enums in the 'Foo' Class retrieve the Enums 'Car' and 'House

Public Class Fo

Public Enum Ca
For
Chevrole
Toyot
Enu

Public Enum Hous
Bungalo
Townhous
Cond
Enu

End Class
 
Faisal said:
Can anyone tell me if it is possible to enumerate through all the
Enums within a class [and not the individual enumerations within a
single Enum]. I have a class with many Enums and would like to accees
the Enums through an array/collection etc. I can't seem to find an
appropriate Reflection method to access Enums within a class.

Use Type.GetNestedTypes, and then check each in turn with Type.IsEnum.
 
Back
Top