views:

507

answers:

6

Hello all,

I am looking for a nice add on to VS 2008 that will let me select all of my private fields and automatically turn them into public properties. Does a tool like this exist?

Thanks

A: 

VS2008 already do that: select a class -> right click class diagram. Here you can design the structure of your class.

Create your fields, then select a field and right click -> Refactoring -> Encapsulate Field...

tanathos
+2  A: 

Visual Studio can do them one at a time (place cursor in field, and CTRL-R, CTRL-E).

ReSharper has a 'fix-up everything' automatic mode, but it is quite agressive and might perform other unwanted changes as well.

There's a list of Visual Studio Refactor shortcuts here.

Jeff Atwood has a list of useful shortcuts here.

Mitch Wheat
hmm, wouldn't it be possible to create a Visual Studio addon that creates the properties in one go, much like it works in Eclipse?
Adam Asham
+1  A: 

The Visual Assist plugin for Visual Studio allows you to do this.

Right click on the member and select 'Refactor'>'Encapsulate field'. Annoyingly it always put the new method bodies in the .h file, but it also allows you to move it to the body using 'Refector'>'Move implementation to source file'. For more details see: http://www.wholetomato.com/

Andy Brice
A: 

You didn't say which language you're using, but Refactor! isn't bad if you're using VB.NET. It doesn't do them all in one go, though.

ChrisA
A: 

I highly recommend RefactorPro!. Its refactorings are quite nice, and I have yet to have it go overboard on a batch replace. Even if it does go overboard, you can always Undo it.

I've been using it for years, and for $99, it's well worth the investment.

Mike Hofer
+1  A: 

You didn't mention if you wanted this because you've got existing code you want to change or if you need to do it as you develop new code. If it is the latter, then in VS 2008, you can type prop and hit tab twice and it will insert a template with a public property and a backing private field. (At least VB does. C# inserts an "automatic" property where you don't see the private field, but it still exists.)

Slapout