Question

I have a common issue when working with code in the IDE:

string.Concat("foo", "bar");

and I need to change it to:

string.Concat("bar", "foo");

Often I have several of these that need to be swapped at once. I would like to avoid all the typing. Is there a way to automate this? Either a shortcut or some sort of macro would be great if I knew where to start.

Edit: changed to string.Concat to show that you can't always modify the method signature. I am only looking to change the order of the params in the method call, and nothing else.

Was it helpful?

Solution

<Ctrl> + <Shift> + <t> will transpose two words, so it would work in your case. Unfortunately I don't see this working (without multiple presses) for functions with larger parameter lists...

OTHER TIPS

There's an option built right into VS for C# code. Go to the method definition, right-click on its name, and click Refactor, Reorder Parameters.

If you need this for C++, you may need to use a regular expression search and replace—if you do, watch out for cases like someMethod("bar", GetOtherThingy("foo", "rofltron")).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top