我正在使用 ReSharper 将静态方法重构为实例方法,但 ReSharper 抛出了一条错误消息:
method has no suitable parameter that can be made into 'this'
这是什么意思?这是我的类方法:
public static DateTime PreviousOrCurrentQuarterEnd(DateTime date)
{
Quarter qrtr = GetQuarter(date);
DateTime endOfQuarter = GetEndOfQuarter(date.Year, qrtr);
if (endOfQuarter == date)
return date;
else
{
DateTime startOfLast = GetStartOfQuarter(date.Year, qrtr);
return startOfLast.AddDays(-1);
}
}
GetEndOfQuarter
和 GetStartOfQuarter
都是同一类中的其他静态方法。
最佳答案
你不需要做任何特殊的事情来使它成为一个实例方法。只需删除静态限定符即可完成。
Resharper 具有将以下静态方法转换为实例方法的功能:
public class MyClass {
public static void DoSomething( MyClass thing, int value) {
thing.Action (value) ;
}
}
成为
public class MyClass {
public void DoSomething( int value) {
this.Action (value) ;
}
}
注意从“事物”到“这个”的变化。
关于c# - Resharper 不允许我将静态方法重构为实例方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17246844/