在使用Resharper提取类之后,有什么方法可以重构“将用法重新命名为其他类上的方法”?

时间:2017-10-17 20:46:29

标签: c# resharper

在我“提取类”之后将几个方法拉入自己的类中,然后我将原始方法包含在调用新类的方法中。还有一个Resharper可以让我做的进一步重构,将所有用法重新用于新类的新方法,然后可能删除旧方法吗?

例如,在Extract Class重构之后,我可能会:

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类的新实例。有什么东西可以帮助我自动完成这项工作的大部分(甚至只是一部分)吗?

1 个答案:

答案 0 :(得分:1)

"Inline Method" refactoring Ctrl + R I )应该可以解决问题。

针对包装器方法运行它,它应该用方法体替换所有用法。

(您可以在方法声明或方法调用中调用它。)

ReSharper - Inline Method

相关问题