How to get Resharper to convert back to a foreach loop
Asked Answered
W

2

11

Resharper 5 can convert my foreachloops to Linq queries. Which I like. But linq is way way way harder to debug than a foreachloop.

When I convert my foreach statement to a linq query, I don't see any option to go back the other way.

Does any one know how to do this? Is it even possible?

West answered 6/7, 2010 at 16:11 Comment(3)
Sounds like it would be worthwhile for Resharper to implement this.Sanskritic
@ Jangwenyi - I can undo the change if I happen to have just done it. But I am talking about if I just found a linq query that is throwing an exception. I was hoping that my query could be converted back to a foreach even though I converted it to a linq query a while ago.West
+1, LINQ looks great but it is miles harder to debug. I've got exactly the same issue, used resharper to convert and now I'm going to have to manually convert back to foreach just so I can tell what's going on. Lesson learned - leave everything as foreach.Batten
B
6

We are working on LINQ2Foreach (and some other) functionality for ReSharper vNext

Brainwash answered 6/7, 2010 at 16:36 Comment(1)
It's been a few years. Is it in the product now? Might be a good time to update this answer.Jeopardous
B
2

I do not believe this is possible. Certainly, it's not listed in the examples of Quick Fixes, where loop-to-LINQ-expression is shown.

What you should be able to do is use the Context Action 'Convert LINQ to methods chain' to go from the 'fluent' style to the 'methods' style, and then selectively use 'Introduce variable' to pull the expression to pieces.

Brotherinlaw answered 6/7, 2010 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.