Tuesday, June 28, 2011

Code refactoring with Visual Studio 2010-Part 3

I have been writing few post about Code refactoring features of visual studio 2010 and This blog post is also one of them. In this post I am going to show you reorder parameters features in visual studio 2010. As a developer you might need to reorder parameter of a method or procedure in code for better readability of the the code and if you do this task manually then it is tedious job to do. But Visual Studio Reorder Parameter code refactoring feature can do this stuff within a minute. So let’s see how its works. For this I have created a simple console application which I have used earlier posts . Following is a code for that.

using System;

namespace CodeRefractoring
{
  class Program
  {
      static void Main(string[] args)
      {
          string firstName = "Jalpesh";
          string lastName = "Vadgama";

          PrintMyName(firstName, lastName);
      }

      private static void PrintMyName(string firstName, string lastName)
      {
          Console.WriteLine(string.Format("FirstName:{0}", firstName));
          Console.WriteLine(string.Format("LastName:{0}", lastName));
          Console.ReadLine();
      }
  }
}

Above code is very simple. It just print a firstname and lastname via PrintMyName method. Now I want to reorder the firstname and lastname parameter of PrintMyName. So for that first I have to select method and then click Refactor Menu-> Reorder parameters like following.

ReOrderParameters

Once you click a dialog box appears like following where it will give options to move parameter with arrow navigation like following.

ReorderParameterDialog

Now I am moving lastname parameter as first parameter like following.

ReOrderParameterAfterReordering

Once you click OK it will show a preview option where I can see the effects of changes like following.

PreviewOption

Once I clicked Apply my code will be changed like following.

using System;

namespace CodeRefractoring
{
  class Program
  {
      static void Main(string[] args)
      {
          string firstName = "Jalpesh";
          string lastName = "Vadgama";

          PrintMyName(lastName, firstName);
      }

      private static void PrintMyName(string lastName, string firstName)
      {
          Console.WriteLine(string.Format("FirstName:{0}", firstName));
          Console.WriteLine(string.Format("LastName:{0}", lastName));
          Console.ReadLine();
      }
  }
}

As you can see its very easy to use this feature. Hoped you liked it.. Stay tuned for more.. Till that happy programming.

Shout it

kick it on DotNetKicks.com
Share:
Monday, June 27, 2011

Code refactoring with Visual Studio 2010 Part-2

In previous post I have written about Extract Method Code refactoring option. In this post I am going to some other code refactoring features of Visual Studio 2010. Renaming variables and methods is one of the most difficult task for a developer. Normally we do like this. First we will rename method or variable and then we will find all the references then do remaining over that stuff. This will be become difficult if your variable or method are referenced at so many files and so many place. But once you use refactor menu rename it will be bit Easy. I am going to use same code which I have created in my previous post. I am just once again putting that code here for your reference.

using System;

namespace CodeRefractoring
{
  class Program
  {
      static void Main(string[] args)
      {
          string firstName = "Jalpesh";
          string lastName = "Vadgama";

          Print(firstName, lastName);
      }

      private static void Print(string firstName, string lastName)
      {
          Console.WriteLine(string.Format("FirstName:{0}", firstName));
          Console.WriteLine(string.Format("LastName:{0}", lastName));
          Console.ReadLine();
      }
  }
}

Now I want to rename print method in this code. To rename the method you can select method name and then select Refactor-> Rename . Once I selected Print method and then click on rename a dialog box will appear like following.

Print

Now I am renaming this Print method to PrintMyName like following.

PrintMyName

Now once you click OK a dialog will appear with preview of code like following. It will show preview of code.

PreviewCode

Now once you click apply. You code will be changed like following.

using System;

namespace CodeRefractoring
{
  class Program
  {
      static void Main(string[] args)
      {
          string firstName = "Jalpesh";
          string lastName = "Vadgama";

          PrintMyName(firstName, lastName);
      }

      private static void PrintMyName(string firstName, string lastName)
      {
          Console.WriteLine(string.Format("FirstName:{0}", firstName));
          Console.WriteLine(string.Format("LastName:{0}", lastName));
          Console.ReadLine();
      }
  }
}
So that’s it. This will work in multiple files also. Hope you liked it.. Stay tuned for more.. Till that Happy Programming.

Shout it

kick it on DotNetKicks.com
Share:
Sunday, June 26, 2011

My blog post appearing on Channel9.msdn.com

Recently I was searching something and I found that one of the post about New Features of the SQL Server Denali was being discussed on Channel9 on MSDN. It’s a great pleasure and honour to have this kind of appreciation. I would like to thanks again Microsoft for giving opportunity and serve community. I would also like to thanks my readers who are giving me all the support and love.

Once again I am appealing good developers to start blogging. I have seen many great developers are who are doing great stuff but not blogging. I would like to say please please do the blogging and share your stuff with community and you will also get this kind of great appreciation.

Here is the link where they discussed that video.

https://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-Skype-HTML-5-Canvas-Python-tools--more

Following is video where Dan and Clint from Microsoft discussed my blog post on channel 9.



Here are the stuff they have discussed during the video.
Once again thank you for great appreciation. Stay tuned for more.. Happy programming.

Shout it
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews