Handle Invoke being called via a method group - #230
Open
simonmckenzie wants to merge 1 commit into
Open
simonmckenzie wants to merge 1 commit into
simonmckenzie wants to merge 1 commit into
Conversation
simonmckenzie
commented
Aug 26, 2026
Comment on lines
+114
to
+123
| if ( | ||
| node.NodeType == ExpressionType.Convert | ||
| && node.Operand is MethodCallExpression methodCall && | ||
| methodCall.Method.Name == "CreateDelegate" | ||
| && methodCall.Method.DeclaringType == typeof(MethodInfo) | ||
| && methodCall.Object is ConstantExpression methodInfoConst | ||
| && methodInfoConst.Value is MethodInfo methodInfo | ||
| && methodInfo.Name == nameof(ExtensionsCore.Invoke) | ||
| && methodInfo.DeclaringType == typeof(ExtensionsCore)) | ||
| { |
Author
simonmckenzie
force-pushed
the
feature/support-invoke-passed-as-method-group
branch
from
August 26, 2026 05:46
2b4fe1f to
ecb2aa5
Compare
simonmckenzie
commented
Aug 26, 2026
| Expression<Func<int, bool>> filter = p => p > 1000; | ||
| Expression<Func<int[], bool>> anyMeetsFilter = x => x.Any(filter.Invoke); | ||
|
|
||
| Assert.Equal("x => x.Any(p => (p > 1000))", anyMeetsFilter.Expand().ToString()); |
Author
There was a problem hiding this comment.
Without the new code, anyMeetsFilter.Expand().ToString() produces this:
x => x.Any(Convert(Boolean Invoke[Int32,Boolean](System.Linq.Expressions.Expression`1[System.Func`2[System.Int32,System.Boolean]], Int32).CreateDelegate(System.Func`2[System.Int32,System.Boolean], p => (p > 1000))))
This addresses an issue where, if `Invoke` is passed via a method group, it's wrapped in `CreateDelegate` and thus isn't inlined. A special handler has been added for this case.
simonmckenzie
force-pushed
the
feature/support-invoke-passed-as-method-group
branch
from
August 27, 2026 22:07
ecb2aa5 to
19ad870
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This addresses an issue where, if
Invokeis passed via a method group, it's wrapped inCreateDelegateand thus isn't inlined. A special handler has been added for this case.Original issue: #229
Context from issue - I feel this is important because refactoring tools naturally suggest replacing lambdas with method groups, which currently breaks

Expand. Refactoring suggestion screenshot is shown below: