Skip to content

"Convert to raw string" fixer which removes indentation and initial blank line from the string value #59591

@jnm2

Description

@jnm2

I've commonly chosen to add whitespace to string values where raw string literals would have been perfect, increasing the readability of the code at the expense of actually having unnecessary whitespace in the string value at runtime:

SomeMethod(@"
    intended first line
    intended second line");

Now that raw strings literals are out, I'd like to be able to fix these all up in bulk to become what I would have written originally, had the feature existed:

SomeMethod(
    """
    intended first line
    intended second line
    """);

In the csharplang discussion on this feature, some people have mentioned writing code this way and using an extension method to remove the indentation at runtime. That means this refactoring use case may also exist in places where the indentation would be significant for the string value itself at runtime.

Perhaps the two current Convert to raw string options could be placed into a submenu, and clicking the top-level menu item could perform the first action within the submenu.

image

Then a third item could be added: Convert to raw string > Remove value indentation and initial empty line

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Complete

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions