Feature request: Convert to interpolated string code refactoring
See original GitHub issueCurrently, there is a code refactoring to convert to verbatim string.
Another possible code refactoring (should only be offered when the string contains {
and }
is to convert to interpolated string.
Example
I wanted something like this while working with unit tests in roslyn and roslyn-analyzer codebases. So, here is an example. Suppose there is an existing unit test like the following
[Fact]
public void TestSomething()
{
var code = @"
namespace Mynamespace
{
public class Program
{
public static void Main() {Console.WriteLine();}
}
}";
}
For some reason, I want to update the unit test to:
[Theory]
[InlineData("")]
[InlineData("string[] args")]
public void TestSomething(string mainArgs)
{
var code = $@"
namespace Mynamespace
{{
public class Program
{{
public static void Main({mainArgs}) {{Console.WriteLine();}}
}}
}}";
}
It would be much easier to make this update if the IDE can offer a refactoring that converts the original code to the following:
var code = $@"
namespace Mynamespace
{{
public class Program
{{
public static void Main() {{}}
}}
}}";
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
c# - "Convert to interpolated string" refactoring suggestion ...
I'm using Visual Studio 2017 Version 15.4.1. Mysteriously and suddenly I am not presented with this option anymore. Where is the "Convert to...
Read more >Convert to String Interpolation | CodeRush
Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu. Select Convert to String Interpolation from the...
Read more >Refactorings - "Convert to string interpolation" ...
Refactorings - "Convert to string interpolation" refactoring produces incorrectly formatted code when applied to a method with wrapped arguments.
Read more >VS2019.4: "Convert to interpolated string" refactoring is not ...
Place the cursor anywhere between the first space and before the } in $" = {ListingId}" or $" = {DealerId}" and bring up...
Read more >C# Quick Actions and Refactorings
Press Ctrl+.to trigger the Quick Actions and Refactorings menu. Select Convert to interpolated string. Convert placeholder to interpolated ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I came up with a new implementation, based on AbstractConvertConcatenationToInterpolatedStringRefactoringProvider and its derived classes (thanks @Youssef1313 for pointing me in the right direction 😉). I will submit a PR shortly.
If it makes any difference, I came here exactly because I expected “Convert to interpolated string” to do just that, precisely because I wanted it since I kept forgetting to add a $.