1
當我將「Extract Class」抽出一些方法到他們自己的類中後,我剩下原來的方法將調用包裝到新類的方法中。 Resharper是否可以讓我做更多的重構,將所有用法重新指派給新類的新方法,然後刪除舊方法?使用Resharper提取類後,有什麼方法可以重構「重用其他類上方法的用法」?
例如,提取類重構之後,我可能有:
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(...) {...}
}
從這裏,我想重新指向FooSource.GetBar和FooSource.GetBarByName的所有用途,而不是用我的新的一個新實例BarSource類。有沒有什麼能夠幫助我自動完成大部分(甚至是部分)這項工作?
謝謝 - 我沒想到這種操作稱爲「內聯」,但它似乎適合。我會試一試。是否有可能一次完成多種方法? –
@PatrickSzalapski我不認爲它是;你必須分別內聯每種方法。 –