5

some days ago i followed an advice of ReSharper to modify all string.Format's to string interpolations. I accepted the suggestion and changed it all throughout the complete solution.

Since we are working in a team, i discussed this change (afterwards, when the damage was done) and we decided to go back to the string.Format's to be sure nothing was broken.

Now, is there a way to tell ReSharper to change all my string interpolations back to string.Format's? I hope there is.

Notes:

  • using Visual Studio 2015
  • using ReSharper 2017.1.3
  • Nothing broke after the change to interpolation, but it's just for esthetic reasons we decided to stay with our string.Format's

It would be great to have an easy way to do this instead of just undoing my checking to TFS (file per file, as there are other changing i want to keep).

5
  • You really find string.Format "nicer" than string interpolation? Commented Jul 26, 2017 at 8:59
  • Not me, but the rest of the team. I would leave it as it is, but well, apparantly once upon a time, someone in the team had something broken using interpolation so therefor the decission Commented Jul 26, 2017 at 9:02
  • 1
    i think sometimes it's nicer/better/more readable to use interpolation and sometimes it's better to use string.Format(f.e. localization or very long texts across multiple lines). It depends. So imo it's not a good dedision to only use one approach. Commented Jul 26, 2017 at 9:09
  • 1
    String interpolation is safer since String.Format can throw exceptions at runtime if the string format isn't compatible with the parameters passed in Commented Sep 12, 2018 at 15:22
  • @TimSchmelter one reason to go back to String.Format is when you generalize your code. In order to reduce duplications, you sometimes need to pass the format to the extracted method. Of course you could keep string interpolation by passing a lambda / an Action instead and but that makes the code only harder to comprehend. Commented Sep 1, 2021 at 7:51

1 Answer 1

5

Put the cursor on a interpolated string | hit Alt+Enter | Convert to 'string.format' | Convert to 'string.format' in solution

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

2 Comments

you are my hero of the day, thanks a lot, it worked!
too bad this doesn't seem to work the other way around

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.