Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio refactoring: Remove method

Is there any Visual Studio Add-In that can do the remove method refactoring?
Suppose you have the following method:

Result DoSomething(parameters)  
{  
    return ComputeResult(parameters);  
}  

Or the variant where Result is void.

The purpose of the refactoring is to replace all the calls to DoSomething with calls to ComputeResult or the expression that uses the parameters if ComputeResult is not a method call.

like image 825
kokos Avatar asked Aug 12 '08 06:08

kokos


People also ask

How do I remove refactoring?

Press Ctrl+Shift+R and then choose Safe Delete. Right-click and choose Refactor | Safe Delete from the context menu.

How do you Refactor in Visual Studio?

If you'd just like to see refactorings without Quick Fixes, you can use the Refactor command (Ctrl+Shift+R). Note: If you prefer to not see the Code Action lightbulb in your editor, you can disable lightbulbs with the editor.


2 Answers

If I understand the question, then Resharper calls this 'inline method' - Ctrl - R + I

like image 130
Will Dean Avatar answered Oct 03 '22 04:10

Will Dean


I would do it the simpliest way:

  1. rename ComputeResult method to ComputeResultX
  2. rename DoSomething method to ComputeResult
  3. remove DoSomething method (which is now ComputeResult)
  4. rename ComputeResultX method back to ComputeResult

Maybe VS will show some conflict because of the last rename, but ignore it.

By "rename" I mean: overwrite the name of the method and after it use the dropdown (Shift+Alt+F10) and select "rename". It will replace all occurences with the new name.

like image 36
Biri Avatar answered Oct 03 '22 04:10

Biri