'Twas the night before X-mas, when all through the house, Not a creature was stirring, not even a mouse; The stockings were hung by the chimney with care, In hopes that DevExpress soon would be there; The children were nestled all snug in their beds, While visions of Refactor! Pro danced in their heads.
Ho, ho, ho! I'm back to stuff your stockings with another feature of Refactor! Pro that lets you leverage Visual Studio 2008 on this fine X-mas Eve.
But wait! Who's that knocking at your front door? Why it's a group of carolers, here to sing a noël for us. Shhh! They're about to begin.
"On the fifth day of X-mas my true love (DevExpress) gave to me..."
One of the tastiest syntactic sugar cookies that has been added to C# 3.0 is Auto-Implemented Properties. This feature allows C# developers to define properties far more concisely than before. Here's how we used to define properties in C# 2.0:
Whew! That's a lot of effort! Thanks to auto-implemented properties, we can now define our properties like so:
Convert to Auto-Implemented Property is a refactoring that can be used to change the first example into the second example. Check out the preview hint below to see everything that this refactoring will do for you.
That's all there is to it! This refactoring does exactly what you expect it to do, and using it will save you dozens of keystrokes.
Unfortunately, our Visual Basic friends aren't feeling the love. You see, auto-implemented properties is a C# 3.0-only feature that did not make it into Visual Basic 9. However, it would be shameful to leave any developer out in the cold. At the request of the Visual Basic team, we've added a new feature that provides the illusion of auto-implemented properties in Visual Basic.
The above screenshot shows what the code looks like as it is being edited. As you can see, no changes have been made yet. However, once the editor caret leaves the property, the field and property automatically collapse onto one line:
View Screencast of VB Property Collapse in Action!
That sleight-of-hand helps VB code appear more concise. I hope this will help our Visual Basic friends feel a warm glow this holiday season.
And with that, I must bid you farewell. Until next time...
He spoke not a word, but went straight to his work, And filled all the stockings; then turned with a jerk, And laying his finger aside of his nose, And giving a nod, up the chimney he rose. He sprang to his sleigh, to his team gave a whistle, And away they all flew, like the down of a thistle: But I heard him exclaim, as he drove out of sight— Merry X-mas to all, and to all a good night.
Page rendered at Tuesday, January 06, 2009 5:52:12 AM (Eastern Standard Time, UTC-05:00)