淘先锋技术网

首页 1 2 3 4 5 6 7

Vs2010重构工具针对C#提供以下方式:

1. 重命名

2. 将方法中的代码提取成新的方法。默认情况是private statid void

3. 将私有变量提取为属性

4. 提取接口

5. 删除方法中的参数

6. 修改方法中的参数,参数顺序

clip_image002[4]

Rename

快捷键:Ctrl+R,R

namespace CSharpTest
{
class Test1
    {
public void TT1()
        {
Console.WriteLine("Hello");
        }
    }
class Program
    {
static void Main(string[] args)
        {
Test1 t = new Test1();
            t.TT1();
        }
    }
}

clip_image004[4]

namespace CSharpTest
{
     class Test1
     {
         public void TT()
         {
             Console.WriteLine("Hello");
         }
 
     }
     class Program
     {
         static void Main(string[] args)
         {
             Test1 t = new Test1();
 
             t.TT();
         }
     }
}

Extract Method

快捷键:Ctrl+R,M

class Test1
     {
         public void TT()
         {
             Console.WriteLine("Hello");
         }
 
     }
     class Program
     {
         static void Main(string[] args)
         {
             Test1 t = new Test1();
 
             t.TT();
         }
     }

clip_image006

 class Test1
     {
         public void TT()
         {
             PrintHello();
         }
 
         private static void PrintHello()
         {
             Console.WriteLine("Hello");
         }
 
     }
     class Program
     {
         static void Main(string[] args)
         {
             Test1 t = new Test1();
 
             t.TT();
         }
     }

Encapsulate Field

快捷键:Ctrl+R,E

       private string name;
        public string Name
         {
             get { return name; }
             set { name = value; }
         }

Extract Interface

快捷键:Ctrl+R,I

clip_image008

提取接口,必须选定一个函数进行多态

Remove Parameters

快捷键:Ctrl+R,V

        public void Test1(int id,int number,int score)
         {
             Console.WriteLine(id);
             Console.WriteLine(number);
             Console.WriteLine(score);
         }
       t.Test1(1, 1000, 90);
 

删除number

        public void Test1(int id, int score)
         {
             Console.WriteLine(id);
            
             Console.WriteLine(score);
         }
       t.Test1(1, 90);

Reorder Parameters

快捷键:Ctrl+R,O

       public void Test1(int id,int number,int score)
         {
             Console.WriteLine(id);
             Console.WriteLine(number);
             Console.WriteLine(score);
         }
 
       t.Test1(1, 1000, 90);

把number和score调换位置

        public void Test1(int id, int score, int number)
         {
             Console.WriteLine(id);
             Console.WriteLine(number);
             Console.WriteLine(score);
         }
       t.Test1(1, 90, 1000);
 

转载于:https://www.cnblogs.com/liangdiamond/archive/2010/12/26/1917348.html