chanshic Yoon
chanshic Yoon

Reputation: 41

How to : rename method return type (C#, Visual Studio)

public interface ILogger
{
    void SaveLog(Log log);
    Log ReadLog();     //To be : List<Log> ReadLog();
    Log ReadLastLog();
}

ReadLog method is used in many classes. I want to change ReadLog return type from Log to List. Ctrl+R+R doesn't work in this case. How can I refactor return type?

Upvotes: 2

Views: 2932

Answers (2)

bugybunny
bugybunny

Reputation: 553

Visual Studio itself only let‘s you refactor the parameters but unfortunately not the return type.

ReSharper offers this functionality with Ctrl+R, S https://www.jetbrains.com/help/resharper/Refactorings__Change_Signature.html

I don‘t know of a free extension that does this.

Upvotes: 1

Svek
Svek

Reputation: 12858

You cannot use rename feature to change Log to List<Log>.

This kind of change changes the type and also the method signature in a way that the rename feature in Visual Studio protects against.

If you really need to, you can do a replace by doing Ctrl+H (Quick Replace) or Edit --> Find and Replace --> (pick one) and make sure you enable all the proper toggles (match case, whole word) and select Entire Solution.

As noted in the comments, this would really introduce some problems and it might not be a good approach for every situation, so use it with caution.

Upvotes: 1

Related Questions