Recently in C# 6 a new language element/syntactic sugar was introduced named string interpolation.
However after a few minutes of enjoying the sweet taste of this syntax, it quickly turns out, that interpolated strings (what are still string literals in semantic point of view) can not be refactored out to a resource because of the variables embedded are living only that scope where the interpolated string is defined.
This scope locked string literals for example can not be localized and regardless of the localization need, some code quality checkers used to regard string literals embedded in as code smell.
Working with a huge enterprise code base I expect to appear more and more interpolated strings, so the problem will be quickly turn from theoretical to practical. I would like both
- have a code quality checker rule which bans out this practice just like string literals in the middle of the code (I can manage it, by defining custom rules in the standard quality tools. Although StyleCop currently does not even recognize them, and runs to an internal error, so this will not be as easy as it sounds)
- have a refactoring tool what can refactor string interpolation to string.Format so then it can easily can refactor out to a standard .NET resource.
Any suggestions
String.Format("My Name is {0}", myName)should beString.Format(project.resources.Introduction, myName).