roslynator icon indicating copy to clipboard operation
roslynator copied to clipboard

Refactoring a method signature for out parameters

Open nvmkpk opened this issue 4 years ago • 4 comments

It would be nice if you can provide a refactoring to replace one or more out parameters of a method to return them (and may be vice versa)

nvmkpk avatar May 17 '20 18:05 nvmkpk

Please provide a code sample.

josefpihrt avatar May 19 '20 04:05 josefpihrt

Something like:

public void Function(string inStr, out int out1, out DateTime out2)
{
...
}

to

public (int, DateTime) Function(string inStr)
{
    int out1;
    DateTime out2;
...

    return (out1, out2);
}

nvmkpk avatar May 22 '20 05:05 nvmkpk

I forgot to mention, I would like to it to make appropriate changes to its caller too.

nvmkpk avatar May 22 '20 05:05 nvmkpk

This refactoring is available as "Transform Out Parameters" in ReSharper: https://www.jetbrains.com/help/resharper/Refactorings_Transform_Parameters.html

xtqqczze avatar Jul 25 '20 15:07 xtqqczze