Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper Convert foreach to LINQ using extension methods

Tags:

c#

linq

resharper

I'm using Resharper 7 and sometimes when I'm writing foreach loops it suggests that I convert it to LINQ. Problem is that I'm unable to find a setting where I can choose that LINQ is created using the extension methods and not in the form of LINQ query.
I know this should be possible because it used to work like that before with my old settings (I had to revert them to default because they got totally broken for some reason).

This is the foreach loop:

var idList= new List<string>();
  foreach (var entity in entityList)
  {
    if(entity.EntityPathOrNull==null)
      idList.Add(entity.Identity);
  }

This is how it is converted:

  var idList = (from entity in entityList where entity.EntityPathOrNull == null select entity.Identity).ToList();

And this is how I want it to look like:

  var idList = entityList.Where(entity => entity.EntityPathOrNull == null).Select(entity=> entity.Identity).ToList();

Question is, does anyone know where this setting is located? I searched and googled everywhere but was unable to find it.

like image 901
Renesis Avatar asked Nov 01 '22 16:11

Renesis


1 Answers

This is the only way I know of to convert it from query syntax. Maybe this can be made the standard action somehow. Elsewise you will have to call it manually or via shortcut.

enter image description here

like image 78
Sebastian Meier Avatar answered Nov 12 '22 09:11

Sebastian Meier