Visual Studio 2017 Code Refactoring – Convert Property To Method

Sometimes you start with creating a class property but later you realised that there is much more work in that property and it’s better to have it as a method. Visual Studio 2017 converting a property to a method quite trivial. Let’s say we have a class Bar with a property BarId as shown below.


Let’s say you want to convert it to a method. For that, you just click on the property name BarId and then bring up Refactoring helper by press “Ctrl + .”. This will pop-up the option for Replacing BarId with methods as shown below. The preview window shows that change that will happen due to this refactoring as well.


Once you preform the refactoring, the code will be changed to have a private field barId and a pair of setter/getter method for this field as shown below.


Until next, happy debugging.

This entry was posted in Visual Studio 2017. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s