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.
Option 1: Cut and paste
This is a new option I added to the answer. This is by far the easiest.
- Cut the code you want to move.
- Paste it in the new location.
- 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.
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.
I recently discovered that it the Move to Folder command does not work in Visual Studio 2022 when one has an active search in the solution explorer. Not sure why, but give that a try.
© 2022 - 2025 — McMap. All rights reserved.
Move
is actually very useful. – Satterfield