Added playlist logic.

This commit is contained in:
2025-02-16 19:07:07 -05:00
parent 8f3b07543f
commit cccf0b57a5
4 changed files with 228 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
using Harmonia.Core.Models;
using System.ComponentModel;
using System.Reflection;
namespace Harmonia.Core.Extensions;
public static class EnumerableExtensions
{
public static IOrderedEnumerable<T> SortBy<T>(this IEnumerable<T> source, SortOption[] sortOptions)
{
IOrderedEnumerable<T> orderedQuery = source.OrderBy(x => 0);
Type type = typeof(T);
foreach (SortOption sortOption in sortOptions)
{
PropertyInfo? property = type.GetProperty(sortOption.FieldName);
if (property == null)
continue;
switch (sortOption.Direction)
{
case ListSortDirection.Ascending:
orderedQuery = orderedQuery.ThenBy(x => property.GetValue(x));
break;
case ListSortDirection.Descending:
orderedQuery = orderedQuery.ThenByDescending(x => property.GetValue(x));
break;
}
}
return orderedQuery;
}
}