Resharper does not allow me to refactor a static method to an instance method

I use ReSharper to refactor a static method for an instance method, but ReSharper throws an error that states:

does not have a suitable parameter that can be done in 'this'

What does it mean? Here is my class method:

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); } } 

Both GetEndOfQuarter and GetStartOfQuarter are other static methods inside the same class.

+4
source share
1 answer

You do not need to do anything special to make this an instance method. Just remove the static classifier and do it.

Resharper has this function to include the following static method in an instance method:

 public class MyClass { public static void DoSomething( MyClass thing, int value) { thing.Action (value) ; } } 

becomes

 public class MyClass { public void DoSomething( int value) { this.Action (value) ; } } 

Note the change from 'stuff' to 'this'.

+4
source

Source: https://habr.com/ru/post/1487588/


All Articles