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

RCS1077 for Select(x => x) #1490

Open
bricelam opened this issue Jul 16, 2024 · 7 comments
Open

RCS1077 for Select(x => x) #1490

bricelam opened this issue Jul 16, 2024 · 7 comments

Comments

@bricelam
Copy link

RCS1077 should recommend removing .Select(x => x).

@BenjaminBrienen
Copy link
Contributor

BenjaminBrienen commented Sep 14, 2024

I'll take this

@josefpihrt
Copy link
Collaborator

@BenjaminBrienen This one can be tricky. In same cases it may be possible to just remove the call but there will be cases where the call is there intentionally to change return from whatever to IEnumerable<T>. And it may be not that easy to determine which case it is.

@BenjaminBrienen
Copy link
Contributor

Good point.

@BenjaminBrienen
Copy link
Contributor

@josefpihrt Could we have 2 code fixes? One that suggests to remove it and another one that suggests AsEnumerable()?

@josefpihrt
Copy link
Collaborator

Yes, there can be two fixes, but you still have an issue how to determine which one it is.

@BenjaminBrienen
Copy link
Contributor

Yes, there can be two fixes, but you still have an issue how to determine which one it is.

I was imagining that the user would just pick one of the two suggestions.

Another strategy would be: We could always suggest AsEnumerable() and then also have a completely separate analyzer that handles unnecessary AsEnumerable() calls. That second analyzer would be the more difficult one to implement.

@josefpihrt
Copy link
Collaborator

josefpihrt commented Sep 15, 2024

We could always suggest AsEnumerable()

Actually, Select(x => x) is not semantically equivalent to .AsEnumerable(). Consider this example:

return list.Select(x => x);

If you change it to

return list.AsEnumerable();

Caller will have direct access to list which was not possible before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants