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.
This is a new option I added to the answer. This is by far the easiest.
I'm not sure if this option will always work.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With