2

I have a method with out parameters like:

void Do(int anInput, out List<string> items, out int count)
{
   /* some code */
}

Now I want to transform that signature so that the out parameters are replaced by an object that is returned by that method like:

DoResult Do(int anInput)
{
   /* some code */
   return new DoResult{Items=TODO, Count=TODO};
}

class DoResult {
    public List<string> Items;
    public int Count;
}

Is there a refactoring for such a transformation in Visual Studio 2010 or ReSharper 7?

I know the ReSharper refactoring Extract Class From Parameters. But it seems it doesn't help me for out parameters.

Update: Daniel A. White's answer is very good for .Net 4.0. Is there a solution for .Net 3.5? Generation of a Tuple is also ok.

7
  • 4
    Do you really need this to be automated? How many places are you going to have to change? It should be fairly easy to do manually. Commented Apr 9, 2013 at 12:48
  • It would propably be a seldom used feature. But I'm lazy. :-) I got the method with 2 out parameters by ReSharper's Extract Method refactoring. Commented Apr 9, 2013 at 13:03
  • But how much work would it be for you to do the refactoring yourself right now, compared with working to find an automated solution? Commented Apr 9, 2013 at 13:06
  • @JonSkeet What do you want? Do you want to help? Do you want that I delete my question. Of course I asked because I think I can save time in future. Commented Apr 9, 2013 at 13:10
  • 2
    @JonSkeet c) JetBrains added this feature to ReSharper. See link in Daniel A. White's answer. Commented Apr 9, 2013 at 13:19

1 Answer 1

3

I found this refactoring in their documentation. It changes it to a Tuple but it should at least get you started.

http://www.jetbrains.com/resharper/webhelp/Refactorings__Transform_Out_Parameters.html

From there, you can do Change Signature.

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

1 Comment

Thank you. Unfortunatly I cannot use that refactoring because it is only possible to transform one out parameter. I think this is so because I have a .NET 3.5 solution. (I added the .net3.5 tag now.)

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.