简体   繁体   English

在 Visual Studio(不是 VS 代码)中为 C# 代码添加自定义缩进

[英]Adding custom indentation for C# code in Visual Studio (not VS Code)

I have C# code as below:我有 C# 代码如下:

Log.Step("step 1");
int x = 10;
int y = 20;

Log.Step("step 2");
int a = 10;
int b = 20;

I want the editor to auto-format those lines as below:我希望编辑器自动格式化这些行,如下所示:

Log.Step("step 1");
    int x = 10;
    int y = 20;

Log.Step("step 2");
    int a = 10;
    int b = 20;

After every Log.Step method, I want to be able to indent the next lines of code till a newline is entered.在每个 Log.Step 方法之后,我希望能够缩进下一行代码,直到输入换行符。 Is there a way I can define indentation rules in VS to do so?有没有一种方法可以在 VS 中定义缩进规则?

Your indentation format is very specific, but there is a approach using { } :您的缩进格式非常具体,但是有一种使用{ }的方法:

static void Main(string[] args)
{
    Log.Step("step 1");
    {
        int x = 10;
        int y = 20;
    }

    Log.Step("step 2");
    {
        int a = 10;
        int b = 20;
    }
}

Is not a "identation" rule, but maybe this can help you不是“身份”规则,但也许这可以帮助你

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

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