Any way to refactor "repoint usages to methods on other class" after extracting a class using Resharper?
After I "Extract Class" to pull out a few methods into their own class, I am then left with the original methods wrapping calls to the new class's methods. Is there a further refactor that Resharper might enable me to do, to repoint all usages to the new methods on the new class, and then perhaps delete the old methods?
For example, after a Extract Class refactoring, I might have:
public class FooSource {
private BarSource _barSource = new BarSource();
public Foo GetFoo(...) {...}
public Foo GetFooByName(...) {...}
public Bar GetBar(...) => _barSource.GetBar(...); // now a wrapper due to refactoring
public Bar GetBarByName(...) => _barSource.GetBarByName(...); // now a wrapper due to refactoring
}
public class BarSource { // my new class just generated by Resharper
private FooSource _fooSource = FooSource(); // sometimes this reference is needed; sometimes not; not relevant to this question
public Bar GetBar(...) {...}
public Bar GetBarByName(...) {...}
}
From here, I want to repoint all usages of FooSource.GetBar and FooSource.GetBarByName to instead use a new instance of my new BarSource class. Is there anything that will help me do most (or even just some) of this work automatically?
(also asked at https://stackoverflow.com/questions/46798947/any-way-to-refactor-repoint-usages-to-methods-on-other-class-after-extracting )
Please sign in to leave a comment.
Try the Inline Method refactoring.
(Also answered on StackOverflow.)