mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 12:14:46 -04:00
Fix contain query param of the api
This commit is contained in:
parent
010fab93d7
commit
4bfffa579f
@ -24,6 +24,7 @@ using System.Linq.Expressions;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Kyoo.Abstractions.Models;
|
using Kyoo.Abstractions.Models;
|
||||||
|
using Kyoo.Utils;
|
||||||
|
|
||||||
namespace Kyoo.Core.Api
|
namespace Kyoo.Core.Api
|
||||||
{
|
{
|
||||||
@ -163,14 +164,34 @@ namespace Kyoo.Core.Api
|
|||||||
|
|
||||||
private static Expression _ContainsResourceExpression(MemberExpression xProperty, string value)
|
private static Expression _ContainsResourceExpression(MemberExpression xProperty, string value)
|
||||||
{
|
{
|
||||||
|
if (xProperty.Type == typeof(string))
|
||||||
|
{
|
||||||
|
// x.PROPRETY.Contains(value);
|
||||||
|
return Expression.Call(xProperty, typeof(string).GetMethod("Contains", new[] { typeof(string) }), Expression.Constant(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
// x.PROPERTY is either a List<> or a []
|
||||||
|
Type inner = xProperty.Type.GetElementType() ?? xProperty.Type.GenericTypeArguments.First();
|
||||||
|
|
||||||
|
if (inner.IsAssignableTo(typeof(string)))
|
||||||
|
{
|
||||||
|
return Expression.Call(typeof(Enumerable), "Contains", new[] { inner }, xProperty, Expression.Constant(value));
|
||||||
|
}
|
||||||
|
else if (inner.IsEnum && Enum.TryParse(inner, value, true, out object enumValue))
|
||||||
|
{
|
||||||
|
return Expression.Call(typeof(Enumerable), "Contains", new[] { inner }, xProperty, Expression.Constant(enumValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inner.IsAssignableTo(typeof(IResource)))
|
||||||
|
throw new ArgumentException("Contain (ctn) not appliable for this property.");
|
||||||
|
|
||||||
// x => x.PROPERTY.Any(y => y.Slug == value)
|
// x => x.PROPERTY.Any(y => y.Slug == value)
|
||||||
Expression ret = null;
|
Expression ret = null;
|
||||||
ParameterExpression y = Expression.Parameter(xProperty.Type.GenericTypeArguments.First(), "y");
|
ParameterExpression y = Expression.Parameter(inner, "y");
|
||||||
foreach (string val in value.Split(','))
|
foreach (string val in value.Split(','))
|
||||||
{
|
{
|
||||||
LambdaExpression lambda = Expression.Lambda(_ResourceEqual(y, val), y);
|
LambdaExpression lambda = Expression.Lambda(_ResourceEqual(y, val), y);
|
||||||
Expression iteration = Expression.Call(typeof(Enumerable), "Any", xProperty.Type.GenericTypeArguments,
|
Expression iteration = Expression.Call(typeof(Enumerable), "Any", new[] { inner }, xProperty, lambda);
|
||||||
xProperty, lambda);
|
|
||||||
|
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
ret = iteration;
|
ret = iteration;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user