By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,492 Members | 3,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,492 IT Pros & Developers. It's quick & easy.

How to enumerate all Enums in a Class

P: n/a
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

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Faisal <faisal.ibrahim@-NOSPAM-dfait-maeci.gc.ca> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

P: n/a
Thanks...the GetNestedTypes method works like a charm.

Faisal

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.