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.

1

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.

2

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.

3

Until next, happy debugging.

Posted in Visual Studio 2017 | Leave a comment

Visual Studio 2017 Code Refactoring – Sync up Class and File names

Sometimes your C# file name and class name are different for whatever reason and you want to fix it. The usual way of “fixing” this issue is either by renaming the file name in solution explorer or changing the class name using Ctrl R + Ctrl R shortcut. None of these are two that bad of options but Visual Studio 2017 has introduced a better way of handle this scenario. Let’s consider following scenario where class name is Foos whereas the file name is Foo.cs.

RenamingFile1

Let’s say the class Foos is used as follows.

RenamingFile3

Within Visual Studio 2017, if you click the cursor on the class name and then press the Quick re-factoring shortcut (Ctrl + .), you will get the two options of either renaming the file or renaming the class as shown in figure below.

RenamingFile2

 

Let’s say I choose to rename the type of Foos to Foo from the menu item. With one click, it will not only rename the class itself but also wherever this class is referred as shown below.

RenamingFile4

 

RenamingFile5

Until next, happy debugging!!

Posted in Uncategorized | Leave a comment

Visual Studio 2017 Code Refactoring – Moving a class into its own file

Visual Studio 2017 has introduced new quick ways to refactor your code. One such refactoring is about moving a class in a new file. There are use cases when a developer may have created many classes in a single file. As shown in figure below, Let’s say I have two classes Foo and Bar in the same file called Foo.cs.

Capture

With Visual Studio 2017 refactoring improvements, its now much easier to move classes into a separate file of its own. In order to do that you just move cursor on the class name Bar within the Editor and right click. This will show the familiar menu options including “Quick Actions and Refactorings”.

Untitled

You can either choose this menu option or the shortcut Ctrl + . which will bring up the new refactoring option of “Move type into Bar.cs”.

Untitled2.png

Once you choose that option, the class Bar will be moved to a new file called Bar.cs as shown in image below.

Capture2

Until next, happy debugging!!!

 

Posted in Visual Studio 2017 | Leave a comment

My presentation about CLR MD for Ottawa .NET Community

Attached is the slide deck.  I need to do some clean up in the demo code. I am hoping to share its link next week.

CLRMD_ODNC

Posted in Uncategorized | Leave a comment

Taking leap from web developer to Windows Store developer – slide deck

WinJS_Presentation
Until next, happy debugging!!!

Posted in Uncategorized | Leave a comment

Slide deck from Ottawa .NET Community presentation

WindowsRunTimeComponents

Until next, happy debugging

Posted in Uncategorized | Leave a comment

Why I am absent from my blog

I know its been a while that I blogged at all. I am excited to share the reason behind it. I am authoring 70-481 Exam Reference book for Microsoft MCSD: Windows Store Apps track. The title of 70-481 exam is Essentials of Developing Windows Store Apps Using HTML5 and JavaScript. You can find this exam objectives here. I will back at blogging regularly once free up with the book.

70481BookImage

Happy Debugging!!!

Posted in Uncategorized | Leave a comment