使用 ReSharper 将扩展方法转换为实例方法?
Converting extension methods to instance methods with ReSharper?
假设我有一个 class:
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
class 并更改 Foo
使其变为:
的最方便方法是什么?
public class Foo
{
public int Bar { get; set; }
public void DoSomething(int someNumber)
{
Bar += someNumber;
}
}
ReSharper 似乎没有提供一步操作来做到这一点(奇怪的是,这似乎是一个非常简单的重构),但我可以结合哪些其他操作来避免太多 copy/pasting手动工作?
显然,是 ReSharper 操作,但它的命名有点尴尬(恕我直言)。它被称为 "Make Method Non-Static"。
可以找到文档 here。请注意,它没有具体提及扩展方法。
相同的重构将适用于其他类型的静态方法(非扩展),这可能解释了命名。
假设我有一个 class:
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
class 并更改 Foo
使其变为:
public class Foo
{
public int Bar { get; set; }
public void DoSomething(int someNumber)
{
Bar += someNumber;
}
}
ReSharper 似乎没有提供一步操作来做到这一点(奇怪的是,这似乎是一个非常简单的重构),但我可以结合哪些其他操作来避免太多 copy/pasting手动工作?
显然,是 ReSharper 操作,但它的命名有点尴尬(恕我直言)。它被称为 "Make Method Non-Static"。
可以找到文档 here。请注意,它没有具体提及扩展方法。
相同的重构将适用于其他类型的静态方法(非扩展),这可能解释了命名。