Insights and outlooks on software development


Visual Studio 2008 tip: prop and propg

Sunday, March 16, 2008 by Thomas L

I'm not trying to steal Sara Ford's job, but this is a tip that tend to be quite overlooked among those who use Visual Studio regularly: the prop/propg syntactic sugar.

Whenever you feel that you'd like to implement a normal boring set-get property that writes to and reads from a private field, just write prop and press Tab. Visual Studio will give you a snippet to fill in:
The code above will create a public getter and setter for the string property Text.

Doing the same with the snippet propg will give us:
This gives us a private setter and public getter.

Since this is only syntactic sugar, I'd like to know what will be generated by the compiler, so I fired up Reflector:
So, a getter and setter, public/public and public/private, respectively, with two private fields. A quite nice way to make the code contain less noise. (Of course, there are other ways as well. :)

Technorati Tags: ,

Filed under having  

0 kommentarer: