views:

521

answers:

3

I've seen it said in other questions that the Linq query syntax compiles to a Lambda.

So why can you not do edit-and-continue when there is a Lambda expression in the method, while with query notation you can?

What's most infuriating, and is seriously making me consider switching to using query notation everywhere, is that even if your code is not in the Lambda, but there's a Lambda somewhere else in the same method, you can't edit-and-continue! That's, like, gratuitous pain inflicted upon unwary developers!

+5  A: 

Edit and continue is able to change method implementations "live", but not what fields are in types.

Lambda expressions (and anonymous methods) can end up creating their own private types when they capture variables. Changing the lambda expression can change the types involved, which would break edit and continue.

It sounds like it should be possible to make changes to the code which don't have this impact, but I suspect it's simply easier to prevent it entirely - which also means you don't start making changes and then find that you're prevented half way through your change.

(Personally I'm not a fan of E&C in the first place, so I've never noticed it.)

Jon Skeet
Shaul
I prefer to use unit tests. Then I don't need to worry about restarting - which means I'm always using fresh code from start to finish.
Jon Skeet
A: 

I don't know for sure, but my guess is the complexity around figuring out what needs to change when there are local variables involved that are lifted to classes. I'm guessing that figuring out what changes would be safe and what wouldn't was deemed to complex and error-prone to get right at this point. The tooling in 2010 focused around threading and the new UI -- maybe we'll get it in the next version.

Jonathan
A: 

I don't know it for sure, but I assume it has to do with the way the compiler converts lambda expressions forming closures into compiler generated classes. Probably there is no (easy) way to apply changes made to the compiled code and preserve the current state.

Daniel Brückner