简体   繁体   English

Visual Studio 缩进字符串

[英]Visual studio indent string

having this string有这个字符串

var commandAfterSerialize = $@"{{""LotId"":""00000000-0000-0000-0000-000000000000"",""AuctionId"":""00000000-0000-0000-0000-000000000000"",""DisableTotalSpendUpdate"":false,""AltInternetSurchargeRate"":null,""WinningBidders"":{{""{winningBidderKey}"":true,""{winningBidderKeySecond}"":false}},""Timestamp"":{timeStampUtc.Ticks},""TimestampUtc"":""{timeStampUtc:o}""}}";

is it possible to display it in better way in visual studio (for editing purpose) without modifing string itself?是否可以在不修改字符串本身的情况下以更好的方式在 visual studio 中显示它(用于编辑目的)? without inserting \r\n into it?不插入\r\n进去?

better formating like json更好的格式,如 json

I am using visual studio 2022, c# 6.0我正在使用 visual studio 2022,c# 6.0

C# 11 C# 11

Allows you to use raw string literals允许您使用原始字符串文字

Example taken from the linked resource:从链接资源中获取的示例:

var xml = """
        <element attr="content">
            <body>
            </body>
        </element>
        """;

Older C# versions较旧的 C# 版本

You can do something like this:你可以这样做:

var xml = "<element attr=\"content\">"+
          "  <body>"+
          "  </body>"+
          "</element>";

Nevermind the XML, this works of course with any string content.没关系 XML,这当然适用于任何字符串内容。


Outside these, I'd like to second @DavidG's comment:在这些之外,我想附和@DavidG 的评论:

If you want to embed larger, more complex JSON in your app, better to put them in a resource file如果你想在你的应用程序中嵌入更大、更复杂的 JSON,最好将它们放在资源文件中

Which has further advantages, as for example you could validate the json. You can have json-specific editor behavior, etc.这还有更多优势,例如您可以验证 json。您可以拥有特定于 json 的编辑器行为等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM