In the most recent version of Resharper 7 from JetBrains, the brilliant team has gone one step above and beyond. Not only do they show this error which can be quite tricky to both understand and fix, but they now go one step further and offer a fix.
For example, look at the below code:
emailDetailIds is actually passed in as a IEnumerable<long> which means that each time I use it, it may be enumerated again. This is a fairly straight forward example as well as the fix, but let’s see what happens when you just ask Resharper to fix it. You get:
This simply does the enumeration once, stores it in a static list and we are done.