RS4: Refactoring a large number of properties.

Given a trivial property like:

int _x;
public int X
{
get{return _x;}
set {_x = value;}
}

If I hover the mouse over the property name, RS gives me the bulb inviting me to convert it to an auto-property and it also displays a tooltip saying the same. I then pulldown the bulb and convert the property to this:

public int X{get;set;}

That's 100% correct. Now, I have about 300+ source files I'm refactoring. Rather than selecting each property name and converting it to an auto-property one at a time, is it possible to select all the properties in a source file that are eligible for conversion so that RS can convert them all to auto-properties in one operation?

2 comments
Comment actions Permalink

Guys, you can ignore this.

I just discovered the Cleanup Code popup menu when I right-click in the source file. I also used, for the first time, the Edit Profiles button. I added a profile that only enables the conversion to auto-properties. Voila! All the properties that are eligible were converted. Fantastic! :)

0
Comment actions Permalink

How can you do this for all readonly properties in a file?

e.g.

int _x;

public int X

{

get{return _x;}

}

There is a refactoring action (To automatic property) for each property but this http://devnet.jetbrains.net/thread/276847 implies that Cleanup Code can't be used to do all readonly properties at once.

As context the class I want to do this to was one that ReSharper created from an anoymous LINQ projection using 'Convert Anonymous to Named Type refactoring' and I chose 'read-only properties with backing fields' which I now want to change to 'auto-properties' without re-doing it all again (there are 60 properties all with attributes on them).

0

Please sign in to leave a comment.