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

267 Views Asked by At

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

3

There are 3 best solutions below

0
SteveC On BEST ANSWER

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

1
Vlad274 On

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.

0
Arwin On

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.