Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tools for refactoring C# public fields into properties

I have a lot of C# code that uses public fields, and I would like to convert them to properties.

I have Resharper, and it will do them one by one, but this will take forever.

Does anyone know of an automated refactoring tool that can help with this?

like image 347
TWA Avatar asked Jun 22 '09 18:06

TWA


2 Answers

Resharper does it very quickly, using Alt+PageDown / ALt+Enter (with the default key bindings). If you are at the first field, Alt+PageDown will jump to the next one (since it'll include wrapping public fields as a suggested refactoring), and Alt+Enter will prompt you to wrap it in a property.

Since you most likely want to avoid a full blanket wrapping of all properties, this is probably the quickest approach. It's quite fast to do this to a class, since it jumps exactly where you need to go...

like image 110
Reed Copsey Avatar answered Sep 28 '22 06:09

Reed Copsey


Refactor fields to properties (no extensions needed):

Refactor C# fields to properties

Step 1: Refactor all fields to be encapsulated by properties

Step 2: Refactor all properties into auto-implemented properties

like image 32
Josh Withee Avatar answered Sep 28 '22 07:09

Josh Withee