Reformatting Arguments String.Format ()

I often find that I am writing something stupid:

String.Format("{1}: {0}", reason, message); 

or something similar, but with a lot more holders in place.

Is there automatic refactoring in Resharper to change the order of place owners and arguments? I tend to ruin the display if I try to reorder manually.

Obviously, the above example is trivial. What I do in reality often writes something like:

 String.Format("{0}.{2} = {1}.{3} AND {0}.{4} = {1}.{5} AND {6}.{7} = {1}.{8}", table1Alias, table2Alias, col1A, col2A, col1B, col2B, table3Alias, col3C, col2C); 

and thought about what would be great if I could move table3Alias ​​to the front alongside other aliases.

(Resharper 7.1.3)

+7
c # resharper
source share
3 answers

No, there are no such functions.

+1
source share

For C # 6+ (Resharper 10+ / 2016+):

  • Place the cursor on the line. Format
  • Press Alt + Enter
  • Select Use string interpolation
  • Press Alt + Enter again
  • Select Convert to string.Format
+3
source share

Just place the cursor in the 3Alias ​​table, then press Ctrl + Alt + Shift + left / right arrow. This changes the order of the parameters in the function call.

It is also possible to delete one of them by pressing Ctrl + Shift + R

enter image description here

There is also a shortcut to add a format element. You can do what you want by combining them. The exact function you are asking for is not implemented.

+1
source share

All Articles