Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReSharper Refactor > Move doesn't work

I have a function I want to move to a different object. In the code, I select the function that I want to move. I use ReSharper > Refactor > Move but nothing happens.

like image 216
Jess Avatar asked Jul 01 '14 12:07

Jess


2 Answers

Option 1: Cut and paste

This is a new option I added to the answer. This is by far the easiest.

  1. Cut the code you want to move.
  2. Paste it in the new location.
  3. An icon will surface that you can click and choose Apply Move Refactoring.

I'm not sure if this option will always work.

Option 2: Add the object you want to move into as a member

I found that Refactor > Move only works if you have that object as a member. The member must be a concrete type, not an interface. For example,

public class MyController : Controller
{
    // ReSharper 8.2 will give the option to move to this object only.
    private MyRepository _repo;

    // ...

    public FunctionToMove()
    {
        // Do stuff.
    }
}

It makes sense when you think about it because ReSharper wants to refactor to working code. You must have a reference to the object in order to call the "moved" method. Even so, Resharper might consider a different UI decision in this case. (Like a message)

Option 3: Change method signature

I was having trouble moving a private method to a static class. I changed the method from private to public static and then I could select the static class I wanted to move it to.

like image 67
Jess Avatar answered Nov 15 '22 04:11

Jess


I was having this problem too, while trying to move a file via the ReSharper Refactor menu. Checking the box "To enable Undo, open all files with changes for editing" in the Move dialog fixed the issue.

like image 28
Sam Magura Avatar answered Nov 15 '22 03:11

Sam Magura