public static IList<T> GetValues<T>()
{
Type enumType = typeof(T);
if (!enumType.IsEnum)
{
return null;
}
IList<T> list = new List<T>();
var fields = from field in enumType.GetFields()
where field.IsLiteral
select field;
foreach (FieldInfo field in fields)
{
object value = field.GetValue(enumType);
list.Add((T)value);
}
returnlist;
}
调用:
IList<City> list = Common.GetValues<City>();