-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
C#: LINQ recommendation queries. #13885
Conversation
0f7b3c6
to
21a11d4
Compare
de93c67
to
f67d5e1
Compare
After inspecting the first DCA run it became evident that the initial version of the narrowing of the LINQ recommendations was to conservative. I have changed the implementation and re-based the PR. Let's see what DCA says before spending more time on review'ing. |
This time the reduction in results look more accurate. |
DCA reports a slowdown for the Jetbrains re-sharper plugin, but I can't reproduce it locally. The logs also look fine. Overall I think the change is good. |
In this PR we fix an issue with the LINQ recommendation queries.
The LINQ related queries provide suggestions for re-writes of foreach statements
where the
exp
is considered enumerable.The expression
exp
is considered enumerable if eithertype
implements theIEnumerable
orIEnumerable<T>
interface.type
implements a public instance methodGetEnumerator()
.However, the LINQ extension methods are only defined on types implementing either the
IEnumerable
orIEnumerable<T>
interface.More specifically,
Select
,All
andWhere
are extension methods onIEnumerable<T>
Cast
andOfType
are extension methods inIEnumerable
.Furthermore, single dimensional arrays (arrays of rank 1) also implement the
IEnumerable<T>
interface: https://learn.microsoft.com/en-gb/dotnet/api/system.array?view=netframework-4.7#remarksThat is, we need to narrow the LINQ recommendation to only those cases.