Asp.net core ASP.NET核心扩展方法将枚举转换为SelectList

Asp.net core ASP.NET核心扩展方法将枚举转换为SelectList,asp.net-core,generics,enums,extension-methods,selectlist,Asp.net Core,Generics,Enums,Extension Methods,Selectlist,我试图为枚举编写一个通用扩展方法,但没有成功,每个扩展方法都会获取一个枚举项而不是枚举列表 public static SelectList GetSelectList<TEnum>(this IQueryable<TEnum> source, bool indexed = false) where TEnum : struct, IConvertible { return new SelectList(Enum.GetValues(typeof(TEnum)).

我试图为枚举编写一个通用扩展方法,但没有成功,每个扩展方法都会获取一个枚举项而不是枚举列表

public static SelectList GetSelectList<TEnum>(this IQueryable<TEnum> source, bool indexed = false) where TEnum : struct, IConvertible
{
    return new SelectList(Enum.GetValues(typeof(TEnum)).Cast<TEnum>().Select(item => new SelectListItem
    {
       Text = "Foo",
       Value = indexed ? "Bar" : "Biz"
    }).ToList(), "Value", "Text");
}
它适用于Item1,但我想像EnumName.GetSelectList(true)一样使用它。
它作为函数运行良好,但我需要作为通用扩展方法来实现它

为什么您需要自己的扩展方法?您可以这样使用:
Html.GetEnumSelectList()
“每个扩展方法都会获得一个枚举项,而不是枚举列表”——这是什么意思?为什么您的方法总是设置固定的
文本
?什么是
索引的
应该是什么意思?@poke这个方法就是一个例子,它运行这个过程,我跳过了这个过程。是否仍要在枚举列表而不是枚举项上应用扩展方法?@TanvirArjel我无权访问.cs方法中的Html
public enum EnumName
{
    Item1=1,
    Item1=2,
}