In .Net it is possible to iterate through an enumeration by using
System.Enum.GetNames(typeof(MyEnum))
or
System.Enum.Ge
I belive this is the same as in the .NET Compact Framework. If we make the assumption that your enum values start at 0 and use every value until their range is over the following code should work.
public static IList GetEnumValues(Type oEnumType)
{
int iLoop = 0;
bool bDefined = true;
List oList = new List();
//Loop values
do
{
//Check if the value is defined
if (Enum.IsDefined(oEnumType, iLoop))
{
//Add item to the value list and increment
oList.Add(iLoop);
++iLoop;
}
else
{
//Set undefined
bDefined = false;
}
} while (bDefined);
//Return the list
return oList;
}
Obviously you could tweak the code to return the enum names or to match diferent patterns e.g. bitwise values.
Here is an alternate version of the method that returns a IList.
public static IList GetEnumValues()
{
Type oEnumType;
int iLoop = 0;
bool bDefined = true;
List oList = new List();
//Get the enum type
oEnumType = typeof(T);
//Check that we have an enum
if (oEnumType.IsEnum)
{
//Loop values
do
{
//Check if the value is defined
if (Enum.IsDefined(oEnumType, iLoop))
{
//Add item to the value list and increment
oList.Add((T) (object) iLoop);
++iLoop;
}
else
{
//Set undefined
bDefined = false;
}
} while (bDefined);
}
//Return the list
return oList;
}