4

I'm using ReSharper to refactor a static method to an instance method, but ReSharper is throwing an error that says:

method has no suitable parameter that can be made into 'this'

What does this 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.

2
  • Please post all of your code for this class. Commented Jun 22, 2013 at 3:20
  • No, it says nothing about line numer or anything. Its a pop up message box that is all it says. No no parameters in constructor, constructors don't have parameters in constructor because there is no constructor. Commented Jun 22, 2013 at 5:19

1 Answer 1

4

You don't need to do anything special to make this an instance method. Just remove the static qualifier and be done.

Resharper has that functionality to turn the following static method into 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) ;
   } 
} 

Notice the change from 'thing' to 'this'.

Sign up to request clarification or add additional context in comments.

3 Comments

well, I could do that but there are like 20+ methods in the class that are all static. I thought there was a way Resharper could refactor the whole class to make it an instance class?
@user1186050 Are you sure you want to do that? If a method can be static, it usually should be. You should think carefully before introducing state like this.
If you check out Make Methods Non-Static it has step by step directions how to do this. After you do it once or twice it doesn't take as long as you might think is totally worth it if the static class is used in more than five or so places.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.