mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Allowing lists to use :eq instead of :ctn
This commit is contained in:
parent
faa908de7b
commit
e2cbbfcd17
@ -78,8 +78,9 @@ namespace Kyoo
|
||||
{
|
||||
Type type = typeof(T);
|
||||
IEnumerable<PropertyInfo> properties = type.GetProperties()
|
||||
.Where(x => x.CanRead && x.CanWrite
|
||||
&& Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null);
|
||||
.Where(x => x.CanRead
|
||||
&& x.CanWrite
|
||||
&& Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null);
|
||||
|
||||
foreach (PropertyInfo property in properties)
|
||||
{
|
||||
@ -101,8 +102,9 @@ namespace Kyoo
|
||||
|
||||
Type type = typeof(T);
|
||||
IEnumerable<PropertyInfo> properties = type.GetProperties()
|
||||
.Where(x => x.CanRead && x.CanWrite
|
||||
&& Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null);
|
||||
.Where(x => x.CanRead
|
||||
&& x.CanWrite
|
||||
&& Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null);
|
||||
|
||||
foreach (PropertyInfo property in properties)
|
||||
{
|
||||
@ -129,8 +131,9 @@ namespace Kyoo
|
||||
|
||||
Type type = typeof(T);
|
||||
IEnumerable<PropertyInfo> properties = type.GetProperties()
|
||||
.Where(x => x.CanRead && x.CanWrite
|
||||
&& Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null);
|
||||
.Where(x => x.CanRead
|
||||
&& x.CanWrite
|
||||
&& Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null);
|
||||
|
||||
foreach (PropertyInfo property in properties)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
@ -51,27 +52,40 @@ namespace Kyoo.CommonApi
|
||||
MemberExpression propertyExpr = Expression.Property(param, property);
|
||||
|
||||
ConstantExpression valueExpr = null;
|
||||
if (operand != "ctn" && !typeof(IResource).IsAssignableFrom(propertyExpr.Type))
|
||||
bool isList = typeof(IEnumerable).IsAssignableFrom(propertyExpr.Type);
|
||||
if (operand != "ctn" && !typeof(IResource).IsAssignableFrom(propertyExpr.Type) && !isList)
|
||||
{
|
||||
Type propertyType = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
|
||||
object val = string.IsNullOrEmpty(value) || value.Equals("null", StringComparison.OrdinalIgnoreCase)
|
||||
object val;
|
||||
try
|
||||
{
|
||||
val = string.IsNullOrEmpty(value) || value.Equals("null", StringComparison.OrdinalIgnoreCase)
|
||||
? null
|
||||
: Convert.ChangeType(value, propertyType);
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
throw new ArgumentException("Comparing two differents value's type.");
|
||||
}
|
||||
|
||||
valueExpr = Expression.Constant(val, property.PropertyType);
|
||||
}
|
||||
|
||||
|
||||
Expression condition = operand switch
|
||||
{
|
||||
"eq" when isList => ContainsResourceExpression(propertyExpr, value),
|
||||
"ctn" => ContainsResourceExpression(propertyExpr, value),
|
||||
|
||||
"eq" when valueExpr == null => ResourceEqual(propertyExpr, value),
|
||||
"not" when valueExpr == null => ResourceEqual(propertyExpr, value, true),
|
||||
|
||||
"eq" => Expression.Equal(propertyExpr, valueExpr),
|
||||
"not" => Expression.NotEqual(propertyExpr, valueExpr!),
|
||||
"lt" => StringCompatibleExpression(Expression.LessThan, propertyExpr, valueExpr),
|
||||
"lte" => StringCompatibleExpression(Expression.LessThanOrEqual, propertyExpr, valueExpr),
|
||||
"gt" => StringCompatibleExpression(Expression.GreaterThan, propertyExpr, valueExpr),
|
||||
"gte" => StringCompatibleExpression(Expression.GreaterThanOrEqual, propertyExpr, valueExpr),
|
||||
"ctn" => ContainsResourceExpression(propertyExpr, value),
|
||||
_ => throw new ArgumentException($"Invalid operand: {operand}")
|
||||
_ => throw new ArgumentException($"Invalid operand: {operand}")
|
||||
};
|
||||
|
||||
if (expression != null)
|
||||
|
@ -4,7 +4,6 @@ using System.Threading.Tasks;
|
||||
using Kyoo.CommonApi;
|
||||
using Kyoo.Controllers;
|
||||
using Kyoo.Models;
|
||||
using Kyoo.Models.Exceptions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 3216846879e75fdc1b9ec4efc1da7599ee6e9e2c
|
||||
Subproject commit 7a9808719933a092e56fc26be8f5c40bf7894e7c
|
Loading…
x
Reference in New Issue
Block a user