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我不认为它是;你必须分别内联每种方法。 –