views:

59

answers:

2

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.

A: 

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")).

Morbo
This only re-orders a signature, not a method call.
Neil N
Reorder Parameters changes both the signature and all calls to it.If what you really want is just to change the method calls and not the signature (it's not super-clear from your original question), you could still refactor as normal, and then quickly return the actual method signature back to what it was before while leaving all of the calls reversed.
Morbo
That assumes I have the ability to change the method. In the case of an external assembly, I can't.
Neil N
It also assumes I want to change ALL OTHER calls to the same method.
Neil N
+1  A: 

<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...

Oren
This comes close, but unfortunately doesn't work for comma delimited params. I end up with something like (,"foo" "bar") or (,foo""bar") perhaps its just the quotes that throw it off. But thanks for the answer.
Neil N
That would be it (the quotes) - looks like a VS bug to me. Sorry...
Oren