Possible Duplicate:
How to enumerate an enum?
So I have a bit of code like this:
enum Decision
{
DecisionA,
DecisionB,
...
}
public void DoStuff(Decision d)
{
switch(d)
{
case Decision.DecisionA:
....
...
}
}
Basically DoStuff
, will do the same thing no matter what the decision, but the decision is used to make what it does more optimal(faster or whatever).
Now, I'd like to implement unit testing for DoStuff. It's fairly easy to test that all the Decisions work properly by having an array like new Decision[]{DecisionA, DecisionB, ...};
However, if I add a decision, I then have to go back and manually add it to the unit test.
Is it possible to just access all of the possible options specified by an enum
? For instance, something like this:
foreach(var d in Decision.Options)
{
//d will be DecisionA, and then DecisionB, etc etc
}