Visual Studio Code 自定义缩进样式

Visual Studio Code 自定义缩进样式

问题描述:

无论出于何种原因(我讨厌它,但它就是这样),我公司的标准样式是将大括号缩进到与它们包含的代码相同的级别,如下所示:

For whatever reason (I hate it, but it is what it is), my company's standard style is to have braces indented to the same level as the code they contain, like this:

public static string StringName
    {
    get
        {
        return "string value";
        }
    }

这在 Visual Studio 中设置起来真的很容易(选项> 文本编辑器> C#(或任何语言)> 代码样式> 格式> 缩进> 缩进左括号和右括号),但我不确定如何自动化这种样式在代码中.除了像 Python 这样标准化缩进的语言,我工作的所有语言都是如此.

This is really easy to set up in Visual Studio (Options > Text Editor > C# (or whatever language) > Code Style > Formatting > Indentation > Indent open and close braces), but I'm unsure how to automate this style in Code. Except for languages like Python where indentation is standardized, this is true of all languages I work in.

如何在 Visual Studio Code 中完成此操作?

How can I accomplish this in Visual Studio Code?

如果您想要 Whitesmiths 风格并且您正在使用 Omnisharp 的 C#:
如果还没有这样的文件,请创建它:omnisharp.json
- 在项目的根目录中,如果您只需要特定项目的格式或
- 在 /.omnisharp 处全局使用它.
里面放:

If you want Whitesmiths style and you're using C# by Omnisharp:
If there is not already such a file, create it: omnisharp.json
- in the root of your project if you want the format just for the particular project or
- at <userdata>/.omnisharp to use it globally.
Inside it put:

{  
"FormattingOptions":  
  {  
  "IndentBraces": true,  
  }  
}

在这里您可以找到格式选项的完整列表.

Here you can find the complete list of formatting options.