Я хочу объединить две функции, которые имеют похожий код, но разные типы переменных. Я хочу использовать тип T внутри IEnumerable, но, похоже, он не работает.
Метод 1:
public static IList<ListItem> AppendTopMakesToList(this IEnumerable<ListItem> options,bool appendSeparatorRow = true)
{
if (options == null || string.IsNullOrEmpty(Sitecore.Configuration.Settings.GetSetting("RACQ.JoinMembership.Top10CarMakes"))) return options.ToList();
var topmakes = Sitecore.Configuration.Settings.GetSetting("RACQ.JoinMembership.Top10CarMakes").Split('|').ToList().ConvertAll(d => d.ToLower());
var filteredMakes = options.Where(x => topmakes.Any(y => y.Contains(x.Text.ToLower()))).ToList();//getting all the makes from the listItems
if (appendSeparatorRow)
{
var separatorListItem = new ListItem("------------------", "------------------", false);
separatorListItem.Attributes.Add("disabled", "true"); //disabling the separator item so that it can't be selected
filteredMakes.Add(separatorListItem);
}
var items = options.ToList();
items.InsertRange(0, filteredMakes);
return items;
}
Метод 2:
public static IList<Make> AppendTopMakesToList(this IEnumerable<Make> options, bool appendSeparatorRow = true)
{
if (options == null || string.IsNullOrEmpty(Sitecore.Configuration.Settings.GetSetting("RACQ.JoinMembership.Top10CarMakes"))) return options.ToList();
var topmakes = Sitecore.Configuration.Settings.GetSetting("RACQ.JoinMembership.Top10CarMakes").Split('|').ToList().ConvertAll(d => d.ToLower());
var filteredMakes = options.Where(x => topmakes.Any(y => y.Contains(x.Code.ToLower()))).ToList();//getting all the makes from the listItems
if (appendSeparatorRow)
{
var separatorListItem = new Make()
{
Code = "------------------",
Description = "------------------"
};
filteredMakes.Add(separatorListItem);
}
var items = options.ToList();
items.InsertRange(0, filteredMakes);
return items;
}
Функции выполняют ту же часть из возвращаемого типа IList и IList, который передается вТип параметра IEnumberable и IEnumberable.