views:

89

answers:

4

Using the standard VS IDE, is there a fast way to create class properties that are linked to the local variables?

The class diagram seems to provide something, but it basically just created a property stub. Is there something better / easier out there ?

A: 

If you're talking about just making quick properties, then Auto-Generated properties are 'the bomb'. There's no need for a background local variable unless you plan to do something special in the get or set.

 public string SampleProperty { get; set; }

or

 public string SampleProperty { get; private set; }

Where you can optionally specify private / protected to limit the property to a setter or getter only. Then, you don't need a local variable and you just use the Property in place of the local variable. The compiler will generate the actual background variable for you.

I think you might be confusing an Auto Generated property with a property stub.

Tejs
+3  A: 

In VS.NET 2008 you can use refactoring, Encapsulate field (ctrl + r, e).
Here is info about how Refactoring In Visual Studio 2008

Jens Granlund
A: 

When building classes in Visual Studio (VS), you can generate property setters and getters quickly by defining a field variable, and then right-clicking on the field and selecting Refactor → Encapsulate Field from the popup menu. VS will display a dialog that lets you approve/change the property name, and optionally, preview changes. When you're satisfied, simply click OK. Voilà! VS generates the property!

Kunal
A: 

You can check this tool from MSDN

http://visualstudiogallery.msdn.microsoft.com/en-us/c736dedf-bbed-454a-8073-89993ca46902

it has a Property Generator and other oprions

rafaelsr