mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Fixing the expression convertor for imbricked lambdas
This commit is contained in:
parent
fb14eb4ef2
commit
75c9d703f7
@ -342,26 +342,18 @@ namespace Kyoo
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal Expression<TTo> VisitAndConvert()
|
internal Expression<TTo> VisitAndConvert()
|
||||||
{
|
|
||||||
return (Expression<TTo>)RunGenericMethod(
|
|
||||||
this,
|
|
||||||
"VisitLambda",
|
|
||||||
_expression.GetType().GetGenericArguments().First(),
|
|
||||||
_expression);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Expression VisitLambda<T>(Expression<T> node)
|
|
||||||
{
|
{
|
||||||
Type returnType = _expression.Type.GetGenericArguments().Last();
|
Type returnType = _expression.Type.GetGenericArguments().Last();
|
||||||
Expression body = node.ReturnType == returnType
|
Expression body = _expression.ReturnType == returnType
|
||||||
? Visit(node.Body)
|
? Visit(_expression.Body)
|
||||||
: Expression.Convert(Visit(node.Body)!, returnType);
|
: Expression.Convert(Visit(_expression.Body)!, returnType);
|
||||||
return Expression.Lambda<TTo>(body!, _newParams);
|
return Expression.Lambda<TTo>(body!, _newParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Expression VisitParameter(ParameterExpression node)
|
protected override Expression VisitParameter(ParameterExpression node)
|
||||||
{
|
{
|
||||||
return _newParams.First(x => x.Name == node.Name);
|
Console.WriteLine($"Rewritting parameter: {node.Name}");
|
||||||
|
return _newParams.FirstOrDefault(x => x.Name == node.Name) ?? node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ namespace Kyoo.CommonApi
|
|||||||
public static Expression<Func<T, bool>> ParseWhere<T>(Dictionary<string, string> where,
|
public static Expression<Func<T, bool>> ParseWhere<T>(Dictionary<string, string> where,
|
||||||
Expression<Func<T, bool>> defaultWhere = null)
|
Expression<Func<T, bool>> defaultWhere = null)
|
||||||
{
|
{
|
||||||
|
return defaultWhere;
|
||||||
|
|
||||||
if (where == null || where.Count == 0)
|
if (where == null || where.Count == 0)
|
||||||
return defaultWhere;
|
return defaultWhere;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user