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

When converting to LINQ calls, omit .Select(x => x) when possible. #39695

Merged
merged 7 commits into from Nov 7, 2019

Conversation

@dpoeschl
Copy link
Member

dpoeschl commented Nov 5, 2019

Fixes #31784

In cases where converting to LINQ calls would leave no LINQ calls at all,
we leave the .Select(x => x) in case the user is trying to do some different
operation.

Fixes #31784

In cases where converting to LINQ calls would leave no LINQ calls at all,
we leave the .Select(x => x) in case the user is trying to do some different
operation.
@dpoeschl

This comment has been minimized.

Copy link
Member Author

dpoeschl commented Nov 5, 2019

@ivanbasov Can we take a look at this together?

@dpoeschl dpoeschl added the Area-IDE label Nov 5, 2019
receiverForInvocation is InvocationExpressionSyntax receiverInvocationExpression)
{
return receiverInvocationExpression;
}

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Nov 5, 2019

Contributor

shouldn't you only do this if !hasForEachChild? Otherwise, this will elide .SelectMany(x => x) right? (can we also add a test for this)?

This comment has been minimized.

Copy link
@dpoeschl

dpoeschl Nov 6, 2019

Author Member

Thanks. Done with code change (but no tests yet).

This comment has been minimized.

Copy link
@dpoeschl

dpoeschl Nov 7, 2019

Author Member

@CyrusNajmabadi Does this look like a good enough example, or were you thinking of something else?

image

This comment has been minimized.

Copy link
@dpoeschl

dpoeschl Nov 7, 2019

Author Member

Added the above as a test: QueryWhichRequiresSelectManyWithIdentityLambda

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Nov 7, 2019

Contributor

That's perfect :)

@dpoeschl dpoeschl marked this pull request as ready for review Nov 7, 2019
@dpoeschl dpoeschl requested a review from dotnet/roslyn-ide as a code owner Nov 7, 2019
@dpoeschl

This comment has been minimized.

Copy link
Member Author

dpoeschl commented Nov 7, 2019

Taking out of Draft state.
Tagging @dotnet/roslyn-ide and @ivanbasov for review. Thanks!

@@ -4,6 +4,7 @@
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions.ConvertLinq

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Nov 7, 2019

Contributor

blank line above ths.

@@ -3864,7 +3903,7 @@ class C
{
void M(IEnumerable<int> nums)
{
int c = (nums.AsQueryable().Select(n1 => n1)).Count();
int c = (nums.AsQueryable()).Count();

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Nov 7, 2019

Contributor

nit: can you file bug about removing these unnecessary parens.

This comment has been minimized.

Copy link
@dpoeschl

dpoeschl Nov 7, 2019

Author Member

Filed as #39727

Copy link
Contributor

ivanbasov left a comment

Looks great!

@dpoeschl dpoeschl merged commit 10fab37 into dotnet:master Nov 7, 2019
18 checks passed
18 checks passed
WIP Ready for review
Details
license/cla All CLA requirements met.
Details
roslyn-CI Build #20191107.7 succeeded
Details
roslyn-CI (Linux_Test coreclr) Linux_Test coreclr succeeded
Details
roslyn-CI (SourceBuild_Test) SourceBuild_Test succeeded
Details
roslyn-CI (Windows_CoreClr_Unit_Tests debug) Windows_CoreClr_Unit_Tests debug succeeded
Details
roslyn-CI (Windows_CoreClr_Unit_Tests release) Windows_CoreClr_Unit_Tests release succeeded
Details
roslyn-CI (Windows_Correctness_Test) Windows_Correctness_Test succeeded
Details
roslyn-CI (Windows_Desktop_Spanish_Unit_Tests) Windows_Desktop_Spanish_Unit_Tests succeeded
Details
roslyn-CI (Windows_Desktop_Unit_Tests debug_32) Windows_Desktop_Unit_Tests debug_32 succeeded
Details
roslyn-CI (Windows_Desktop_Unit_Tests debug_64) Windows_Desktop_Unit_Tests debug_64 succeeded
Details
roslyn-CI (Windows_Desktop_Unit_Tests release_32) Windows_Desktop_Unit_Tests release_32 succeeded
Details
roslyn-CI (Windows_Desktop_Unit_Tests release_64) Windows_Desktop_Unit_Tests release_64 succeeded
Details
roslyn-CI (Windows_Determinism_Test) Windows_Determinism_Test succeeded
Details
roslyn-CI (macOS_Test) macOS_Test succeeded
Details
roslyn-integration-CI Build #20191107.7 succeeded
Details
roslyn-integration-CI (VS_Integration debug_async) VS_Integration debug_async succeeded
Details
roslyn-integration-CI (VS_Integration release_async) VS_Integration release_async succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.