Code refactoring with Visual Studio 2010-Part 3

Posted by Jalpesh P. Vadgama on ASP.net Weblogs See other posts from ASP.net Weblogs or by Jalpesh P. Vadgama
Published on Tue, 28 Jun 2011 09:52:20 GMT Indexed on 2011/06/28 16:23 UTC
Read the original article Hit count: 456

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

© ASP.net Weblogs or respective owner

Related posts about ASP.NET

Related posts about c#.net