Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add additional check for method/fetches in TestQueryable/ExpressionTreeModifier #21

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autoformatting?

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