using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
public static class ListSorter
{
public static List SortByProperty(List list, string propertyName, bool descending = false)
{
if (string.IsNullOrEmpty(propertyName)) return list;
PropertyInfo prop = typeof(T).GetProperty(propertyName,
BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
if (prop == null) throw new ArgumentException($"Property '{propertyName}' not found.");
return descending
? list.OrderByDescending(x => prop.GetValue(x, null)).ToList()
: list.OrderBy(x => prop.GetValue(x, null)).ToList();
}
}