我正在检查排序参数并构建一堆if
语句:
if (sortDirection == "ASC")
{
if (sortBy == "Id")
return customerList.OrderBy(x => x.Id).Skip(startIndex).Take(pageSize).ToList();
if (sortBy == "FirstName")
return customerList.OrderBy(x => x.FirstName).Skip(startIndex).Take(pageSize).ToList();
if (sortBy == "City")
return customerList.OrderBy(x => x.City).Skip(startIndex).Take(pageSize).ToList();
}
else
{
if (sortBy == "Id")
return customerList.OrderByDescending(x => x.Id).Skip(startIndex).Take(pageSize).ToList();
if (sortBy == "FirstName")
return customerList.OrderByDescending(x => x.FirstName).Skip(startIndex).Take(pageSize).ToList();
if (sortBy == "City")
return customerList.OrderByDescending(x => x.City).Skip(startIndex).Take(pageSize).ToList();
}
我怎样才能使它变得更好?