How to stop Resharper toggling between Enumerable.ToList and Select suggestion
Asked Answered
H

3

12

If I use the Resharper code cleanup function, I'm finding my code ...

var personInfos = persons.Select(Mapper.Map<PersonInfo>).ToList();

is changed to ...

var personInfos = Enumerable.ToList(persons.Select(Mapper.Map<PersonInfo>));

But then Resharper makes a suggestion "To extension method invocation" for the Enumerable.ToList so the code goes back to ...

var personInfos = persons.Select(Mapper.Map<PersonInfo>).ToList();

I've checked in the Resharper code editing options, but I can't see where/how I can stop this toggling behaviour

Hairworm answered 18/11, 2015 at 11:41 Comment(0)
H
3

I think @Matthias may be correct

I've updated to current Resharper, i.e. 2016.1.2 and tried the code ...

var personInfos = persons.Select(Mapper.Map<PersonInfo>).ToList();

Resharper no longer offers a suggestion

And @Vlad274 this is with my code cleanup Optimise 'using' directives and Shorten qualified references both still checked

Hairworm answered 10/8, 2016 at 10:12 Comment(0)
S
0

To fix this you'll need to create a custom cleanup profile. The two settings that need to be turned off are highlighted below.

Settings

By default, the full cleanup has both settings turned on. If either setting is turned on, the cleanup will make this switch.

Scrimp answered 3/8, 2016 at 22:1 Comment(1)
If this is really the case, it sounds like a bug to me and you should report it to youtrack.jetbrains.com. Those two options are clearly not responsible for swapping between static and extension invocation. I have both options enabled, and the usual instance-like invocation is kept.Macey
M
0

As an alternative to upgrading and perhaps a more general solution:

Under the code inspection menu you should have inspection 'Convert static method invocation ... ' there is an option called 'configure inspection severity'. Here you should be able to select: do not show.

Works best of course if you save these preferences into a shared settings file so that all working on this solution share this setting automatically.

Monohydric answered 10/8, 2016 at 12:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.