Skip to content

Feature request: Convert to interpolated string code refactoring #48219

@Youssef1313

Description

@Youssef1313

Currently, there is a code refactoring to convert to verbatim string.

image

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() {{}}
    }}
}}";

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEFeature RequestIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions