Make shorthand auto-index string literals to stay consistent with a set of code

In C #, I often use verbatim string literals (e.g. @"Arrr!") to split long strings into multiple strings while keeping the layout. For example, I use it to break inline SQL as follows:

var sqlString = @" 
    SELECT 
        Column1
        , ...
    FROM
        Table1 INNER JOIN ...
    WHERE 
        Column2 = @Value2
        , ...
    ";

... or break up the regular expression pattern as follows:

var regexPattern = @"
    (?<state>\w+)[.]?                       (?#*** Matches state {optionally having a period at the end} ***)
    (\s+|,|,\s+|\s*\u2022\s*)               (?#*** Matches space between state and zip {can include a comma or bullet point} ***)
    (?<zip>(\d{5}-\d{4}\b|\d{5}(?![\w-])))  (?#*** Matches zip code ***)
    ";

 

If this code subsequently automatically retreats, the verbatim literal will not automatically retreat. It is left behind, and the lines of code above and below are to the right. As a result, he falls out of balance with everything else. For instance:

BEFORE:

verbatim = @"               ___
    I likes my                 |
    strings purty              | indented the way I like!
    ";                      ___|
fooBar = "nomnom";

AFTER THE ENVIRONMENT WITH ANSWERED "IF":

if (true)
{
    if (maybe)
    {
        verbatim = @"       ___
    I likes my                 |
    strings purty              | no longer indented the way I like =(
    ";                      ___|
        fooBar = "nomnom";
    }
}

 

How can I make Auto-indent Visual Studio string literal strings exactly the same as with other lines of code?

 

  • ( , , ):

    notverbatim = 
        "Alas! " 
        + "This doth " 
        + "make me sad =( " 
        ; 
    
  • " ", , , , . Visual Studio, , , , , ,

+4

All Articles