【问题标题】:Converting extension methods to instance methods with ReSharper?使用 ReSharper 将扩展方法转换为实例方法?
【发布时间】:2016-06-06 15:10:12
【问题描述】:

假设我有一堂课:

public class Foo
{
    public int Bar { get; set; }
}

还有一个扩展方法:

public static class FooExtensions
{
    public static void DoSomething(this Foo foo, int someNumber)
    {
        foo.Bar += someNumber;
    }
}

删除FooExtensions 类并更改Foo 最方便的方法是:

public class Foo
{
    public int Bar { get; set; }

    public void DoSomething(int someNumber)
    {
        Bar += someNumber;
    }
}

ReSharper 似乎没有提供一步操作来做到这一点(奇怪的是,这似乎是一个非常简单的重构),但我可以结合哪些其他操作来避免过多的复制/粘贴和手动工作?

【问题讨论】:

    标签: c# .net visual-studio refactoring resharper


    【解决方案1】:

    显然, 有一个 ReSharper 操作用于此,但它的命名有点尴尬(恕我直言)。它被称为“使方法非静态”。

    可以在here 找到文档。请注意,它没有具体提及扩展方法。

    相同的重构将适用于其他类型的静态方法(非扩展),这可能解释了命名。

    【讨论】:

      猜你喜欢
      • 2011-04-25
      • 1970-01-01
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-10
      相关资源
      最近更新 更多