using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Wayne.Lib
{
///
/// Enumsupport is a class that has the goal to provide the functionality offered by System.Enum class, but that
/// are not available in compact framework. It is very limited in some aspects, so please read carefully the comments of each method.
///
public static class EnumSupport
{
///
/// Gets a list of the enumerated value names for the specified enumeration type.
/// NOTE: The enum must not have explicit values set, so there are gaps in the value range, it must start at 0 and go up to max.
///
///
///
public static string[] GetNames()
{
Type type = typeof(TEnumType);
if (!type.IsEnum)
throw new ArgumentException("Type must be an enumeration.");
List names = new List();
int i = 0;
while (System.Enum.IsDefined(type, i))
{
object oInt = i;
TEnumType enumVal = (TEnumType)oInt;
object oEnum = enumVal;
names.Add((oEnum).ToString());
i++;
}
return names.ToArray();
}
///
/// Gets a list of the enumerated values for the specified enumeration type.
/// NOTE: The enum must not have explicit values set, so there are gaps in the value range, it must start at 0 and go up to max.
///
///
///
public static TEnumType[] GetValues()
{
Type type = typeof(TEnumType);
if (!type.IsEnum)
throw new ArgumentException("Type must be an enumeration.");
List values = new List();
int i = 0;
while (System.Enum.IsDefined(type, i))
{
object o = i;
TEnumType et = (TEnumType)o;
values.Add(et);
i++;
}
return values.ToArray();
}
///
/// Gets a list of the enumerated values for the specified enumeration type.
/// NOTE: The enum must not have explicit values set, so there are gaps in the value range, it must start at 0 and go up to max.
///
///
/// Only values of this type are returned
///
public static List