473,382 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to enumerate all Enums in a Class

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
2 2039
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
Thanks...the GetNestedTypes method works like a charm.

Faisal

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Mark A. Gibbs | last post by:
i have been toying with the idea of making my enums smarter - ie, more in line with the rest of the language. i haven't tested it yet, but what i came up with is a template like this: template...
4
by: Martin Pritchard | last post by:
Hi, I'm working on a project that historically contains around 40 enums. In the database various fields refer to the int values of these enums, but of course ref integrity is not enofrced and...
2
by: Faisal | last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't...
2
by: Paul | last post by:
I have a situation that I want to work but don't know the proper way to handle it. I want to create a User Defined "Type" (structure, class or enumeration). I'm not sure what it should be or...
2
by: Faisal | last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't...
3
by: lou zion | last post by:
hi all, i'm trying to use a classes enums in another class, but can't seem to find the right syntax. i've got class A which has: enum EditTypeA {Currency, Percent, LabeledNumber, Text};...
2
by: Simon Elliott | last post by:
I have some legacy C++ code which requires some enums to be 1 or 2 bytes in size. I'd ideally like to be able to specify that a few carefully selected enums are a particular size. By default,...
13
by: Bob | last post by:
Hi, Can someone explain why you can't declare enums in an interface? The compiler says "interfaces can't declare types" Ignoring the syntax implications it seems to me that you should be able to...
3
by: =?Utf-8?B?Sm9uYXRoYW4gU21pdGg=?= | last post by:
I have a class as follows: class GamesConsole { public int iReference; public enum Maker {Nintendo, Sega, Sony, Panasonic} }
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.