mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-03 05:34:23 -04:00
Fix episodes comparison
This commit is contained in:
parent
e0b2e8e937
commit
bd84989454
@ -152,8 +152,17 @@ public abstract record Filter<T> : Filter
|
|||||||
|
|
||||||
private static Parser<object> _GetValueParser(Type type)
|
private static Parser<object> _GetValueParser(Type type)
|
||||||
{
|
{
|
||||||
|
Type? nullable = Nullable.GetUnderlyingType(type);
|
||||||
|
if (nullable != null)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
from value in _GetValueParser(nullable)
|
||||||
|
select value;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == typeof(int))
|
if (type == typeof(int))
|
||||||
return Parse.Number.Select(x => int.Parse(x) as object);
|
return Parse.Number.Select(x => int.Parse(x) as object);
|
||||||
|
|
||||||
if (type == typeof(float))
|
if (type == typeof(float))
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
@ -137,15 +137,24 @@ namespace Kyoo.Core.Controllers
|
|||||||
|
|
||||||
BinaryExpression StringCompatibleExpression(
|
BinaryExpression StringCompatibleExpression(
|
||||||
Func<Expression, Expression, BinaryExpression> operand,
|
Func<Expression, Expression, BinaryExpression> operand,
|
||||||
Expression left,
|
string property,
|
||||||
Expression right)
|
object value)
|
||||||
{
|
{
|
||||||
|
var left = Expression.Property(x, property);
|
||||||
|
var right = Expression.Constant(value, ((PropertyInfo)left.Member).PropertyType);
|
||||||
if (left.Type != typeof(string))
|
if (left.Type != typeof(string))
|
||||||
return operand(left, right);
|
return operand(left, right);
|
||||||
MethodCallExpression call = Expression.Call(typeof(string), "Compare", null, left, right);
|
MethodCallExpression call = Expression.Call(typeof(string), "Compare", null, left, right);
|
||||||
return operand(call, Expression.Constant(0));
|
return operand(call, Expression.Constant(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Expression Exp(Func<Expression, Expression, BinaryExpression> operand, string property, object? value)
|
||||||
|
{
|
||||||
|
var prop = Expression.Property(x, property);
|
||||||
|
var val = Expression.Constant(value, ((PropertyInfo)prop.Member).PropertyType);
|
||||||
|
return operand(prop, val);
|
||||||
|
}
|
||||||
|
|
||||||
Expression Parse(Filter<T> f)
|
Expression Parse(Filter<T> f)
|
||||||
{
|
{
|
||||||
return f switch
|
return f switch
|
||||||
@ -153,12 +162,12 @@ namespace Kyoo.Core.Controllers
|
|||||||
Filter<T>.And(var first, var second) => Expression.AndAlso(Parse(first), Parse(second)),
|
Filter<T>.And(var first, var second) => Expression.AndAlso(Parse(first), Parse(second)),
|
||||||
Filter<T>.Or(var first, var second) => Expression.OrElse(Parse(first), Parse(second)),
|
Filter<T>.Or(var first, var second) => Expression.OrElse(Parse(first), Parse(second)),
|
||||||
Filter<T>.Not(var inner) => Expression.Not(Parse(inner)),
|
Filter<T>.Not(var inner) => Expression.Not(Parse(inner)),
|
||||||
Filter<T>.Eq(var property, var value) => Expression.Equal(Expression.Property(x, property), Expression.Constant(value)),
|
Filter<T>.Eq(var property, var value) => Exp(Expression.Equal, property, value),
|
||||||
Filter<T>.Ne(var property, var value) => Expression.NotEqual(Expression.Property(x, property), Expression.Constant(value)),
|
Filter<T>.Ne(var property, var value) => Exp(Expression.NotEqual, property, value),
|
||||||
Filter<T>.Gt(var property, var value) => StringCompatibleExpression(Expression.GreaterThan, Expression.Property(x, property), Expression.Constant(value)),
|
Filter<T>.Gt(var property, var value) => StringCompatibleExpression(Expression.GreaterThan, property, value),
|
||||||
Filter<T>.Ge(var property, var value) => StringCompatibleExpression(Expression.GreaterThanOrEqual, Expression.Property(x, property), Expression.Constant(value)),
|
Filter<T>.Ge(var property, var value) => StringCompatibleExpression(Expression.GreaterThanOrEqual, property, value),
|
||||||
Filter<T>.Lt(var property, var value) => StringCompatibleExpression(Expression.LessThan, Expression.Property(x, property), Expression.Constant(value)),
|
Filter<T>.Lt(var property, var value) => StringCompatibleExpression(Expression.LessThan, property, value),
|
||||||
Filter<T>.Le(var property, var value) => StringCompatibleExpression(Expression.LessThanOrEqual, Expression.Property(x, property), Expression.Constant(value)),
|
Filter<T>.Le(var property, var value) => StringCompatibleExpression(Expression.LessThanOrEqual, property, value),
|
||||||
Filter<T>.Has(var property, var value) => Expression.Call(typeof(Enumerable), "Contains", new[] { value.GetType() }, Expression.Property(x, property), Expression.Constant(value)),
|
Filter<T>.Has(var property, var value) => Expression.Call(typeof(Enumerable), "Contains", new[] { value.GetType() }, Expression.Property(x, property), Expression.Constant(value)),
|
||||||
Filter<T>.CmpRandom(var op, var seed, var refId) => CmpRandomHandler(op, seed, refId),
|
Filter<T>.CmpRandom(var op, var seed, var refId) => CmpRandomHandler(op, seed, refId),
|
||||||
Filter<T>.Lambda(var lambda) => ExpressionArgumentReplacer.ReplaceParams(lambda.Body, lambda.Parameters, x),
|
Filter<T>.Lambda(var lambda) => ExpressionArgumentReplacer.ReplaceParams(lambda.Body, lambda.Parameters, x),
|
||||||
|
@ -54,7 +54,7 @@ public class RepositoryHelper
|
|||||||
{
|
{
|
||||||
sort ??= new Sort<T>.Default();
|
sort ??= new Sort<T>.Default();
|
||||||
|
|
||||||
IEnumerable<SortIndicator> GetSortsBy(Sort<T> sort)
|
static IEnumerable<SortIndicator> GetSortsBy(Sort<T> sort)
|
||||||
{
|
{
|
||||||
return sort switch
|
return sort switch
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user