我想转换这个方法
public static List<T> GetAllEnumValues<T>() where T : Enum
{
return Enum.GetValues(typeof(T)).Cast<T>().ToList();
}
进入扩展。
这样我就可以像这样使用它
Countries.GetAllEnumValues();
而不是这个
GenericMethods.GetAllEnumValues<Countries>()
有没有一种方法可以在不传递要扩展的类型的实例的情况下创建扩展?
我会想象这样的事情......
public static List<T> GetAllEnumValues<this T>() where T : Enum //not compiling for obvious reasons
{
return Enum.GetValues(typeof(T)).Cast<T>().ToList();
}