Skip to content

Commit

Permalink
add additional check for method/fetches in TestQueryable/ExpressionTr…
Browse files Browse the repository at this point in the history
…eeModifier (#21)

* add additional check for method/fetches in TestQueryable/ExpressionTreeModifier

* up version
  • Loading branch information
ivan-luxoft authored Sep 20, 2024
1 parent 8c86c61 commit 00eb725
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,26 @@ protected override Expression VisitMethodCall(MethodCallExpression node)

var fetchInput = AvoidFetch(node);
return fetchInput.NodeType switch
{
ExpressionType.Constant => this.VisitConstant((ConstantExpression)fetchInput),
_ => fetchInput
};
{
ExpressionType.Constant => this.VisitConstant((ConstantExpression)fetchInput),
_ => fetchInput
};
}

private static Expression AvoidFetch(MethodCallExpression node) =>
IsFetchMethod(node.Method) ? AvoidFetch((node.Arguments[0] as MethodCallExpression)!) : node;
private static Expression AvoidFetch(MethodCallExpression node)
{
if (!IsFetchMethod(node.Method))
{
return node;
}

return node.Arguments[0] switch
{
ConstantExpression constantExpression => constantExpression,
MethodCallExpression methodCallExpression => AvoidFetch(methodCallExpression),
_ => throw new ArgumentOutOfRangeException($"Not handled case - first argument is '{node.Arguments[0].GetType().Name}'")
};
}

private static bool IsFetchMethod(MethodInfo info) =>
info.IsGenericMethod && VisitedMethods.Contains(info.GetGenericMethodDefinition());
private static bool IsFetchMethod(MethodInfo info) => info.IsGenericMethod && VisitedMethods.Contains(info.GetGenericMethodDefinition());
}
6 changes: 3 additions & 3 deletions src/__SolutionItems/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[assembly: AssemblyCompany("Luxoft")]
[assembly: AssemblyCopyright("Copyright © Luxoft 2024")]

[assembly: AssemblyVersion("1.5.5.0")]
[assembly: AssemblyFileVersion("1.5.5.0")]
[assembly: AssemblyInformationalVersion("1.5.5.0")]
[assembly: AssemblyVersion("1.5.6.0")]
[assembly: AssemblyFileVersion("1.5.6.0")]
[assembly: AssemblyInformationalVersion("1.5.6.0")]

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
Expand Down

0 comments on commit 00eb725

Please sign in to comment.