5

Suppose I have a class:

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

And an extension method:

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

What would be the most convenient way to remove the FooExtensions class and alter Foo so it becomes:

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

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

ReSharper doesn't seem to offer a one-step action to do this (strangely enough as this seems a pretty straightforward refactoring), but which other actions might I combine to avoid too much copy/pasting around and manual work?

1 Answer 1

4

Apparently, there is a ReSharper action for this, but it is named a bit awkwardly (imho). It's called "Make Method Non-Static".

The documentation can be found here. Note that it doesn't mention extension methods specifically.

The same refactoring will work for other kinds of static methods (non-extension), which probably explains the naming.

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

Comments

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.