Archive for April 11th, 2008

Generating object initializers with ReSharper

Friday, April 11th, 2008

ReSharper provides both a quick-fix and a context action to transform assignment statements into C# object initializers, and both are called “Use object initializer”.
 
So what’s the difference between them?
 
Suppose that you create an object with three assignment statements:
 

 
Putting the caret over the “new” keyword lets you apply a quick-fix that will put all assigned fields into an object initializer:
 

 
Putting the caret over the object variable or a field name in any of the tree assignment statements lets you apply a context action that will put only this assignment in the object initializer:
 

 
That is, using the context action, you can selectively put field assignments into the object initializer, leaving some of them to be declared explicitly.

Technorati tags: , , , ,

Feedback received

Friday, April 11th, 2008

Thanks for sharing your thoughts and demands in the previous post. Your input will hopefully push us to pay more attention to screencasting in the near future.
 
Meanwhile, in case that you’ve missed it, take a look at our existing collection of demos.