简体   繁体   中英

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

I have C# code as below:

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. Is there a way I can define indentation rules in VS to do so?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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