How to enumerate all Enums in a Class

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
 
J

Jon Skeet [C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top