mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-27 10:07:10 +00:00
f4dd6adc6a
Allow specials in missing Dropped ListSortDirection
48 lines
No EOL
1.6 KiB
C#
48 lines
No EOL
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
|
|
namespace NzbDrone.Core.Datastore
|
|
{
|
|
public static class PagingSpecExtensions
|
|
{
|
|
public static Expression<Func<TModel, object>> OrderByClause<TModel>(this PagingSpec<TModel> pagingSpec)
|
|
{
|
|
return CreateExpression<TModel>(pagingSpec.SortKey);
|
|
}
|
|
|
|
public static int PagingOffset<TModel>(this PagingSpec<TModel> pagingSpec)
|
|
{
|
|
return (pagingSpec.Page - 1)*pagingSpec.PageSize;
|
|
}
|
|
|
|
public static Marr.Data.QGen.SortDirection ToSortDirection<TModel>(this PagingSpec<TModel> pagingSpec)
|
|
{
|
|
if (pagingSpec.SortDirection == SortDirection.Descending) return Marr.Data.QGen.SortDirection.Desc;
|
|
|
|
return Marr.Data.QGen.SortDirection.Asc;
|
|
}
|
|
|
|
private static Expression<Func<TModel, object>> CreateExpression<TModel>(string propertyName)
|
|
{
|
|
Type type = typeof(TModel);
|
|
ParameterExpression parameterExpression = Expression.Parameter(type, "x");
|
|
Expression expressionBody = parameterExpression;
|
|
|
|
var splitPropertyName = propertyName.Split('.').ToList();
|
|
|
|
foreach (var property in splitPropertyName)
|
|
{
|
|
expressionBody = Expression.Property(expressionBody, property);
|
|
}
|
|
|
|
expressionBody = Expression.Convert(expressionBody, typeof(object));
|
|
return Expression.Lambda<Func<TModel, object>>(expressionBody, parameterExpression);
|
|
}
|
|
}
|
|
}
|
|
|