views:

67

answers:

2

Hi all,

I have a project with a bunch of classes with methods that look like this:

public class Person {
    private string _name;
    ...

    public void setName(string name) {
        this._name = name;
    }
    public string getName()
    {
        return this._name;
    }
    ....
}

Is there a way to get reSharpers Code cleanup feature (or any other tool out there) to refactor the above code to this.

public class Person {
    public string Name { get; set; }
}

I'm guessing there isn't any tool that does this, but it never hurts to ask right?

Thanks

+1  A: 

DevExpress Refactor! Pro has a "Convert to Auto-implemented Property" refactoring.

dahlbyk
Thanks. I just noticed that Resharper has this feature as well. It was under the "Refactor This" command.
Newbie
A: 

You can use Resharper Cleanup code feature which is available with the Stylecop for Resharper plugin. It can do lot of things for you like

  • remove redundant qualifier convert properties to automatic
    properties convert members to
    readonly variables if applicable
    Format code like removing extra line breaks, alignement of braces etc.

These are just very few things. For a complete working example you can visit my blog on Cleanup code http://nileshgule.blogspot.com/2010/10/refactoring-clean-code-using-resharper.html

Nilesh Gule