Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Extract Variable" in Visual Studio without ReSharper

Tags:

I don't have ReSharper at my current gig, and I miss the "Extract Variable" refactoring. I understand that it's possible to write your own refactoring "snippet" in VS. Does anybody have one that does this?

like image 202
Justin R. Avatar asked Apr 05 '11 03:04

Justin R.


2 Answers

In Visual Studio 2017, if you select something, on right-click you will find a menu option "Quick Actions and Refactorings", with shortcut ctrl+..
This seems to be somewhat similar to ReSharper's ALT+Enter.

This allows you to extract a variable, as in this example where the text was selected and then ctrl+. was pressed: extracting a constant

like image 88
ANeves Avatar answered Oct 25 '22 10:10

ANeves


Have a look at this post, but it does not seem to be a documented feature.

Another way would be a write a macro using the EnvDTE programming model. Not easy, but should be feasible.

like image 36
Timores Avatar answered Oct 25 '22 09:10

Timores