C# 使用 ReSharper 在 Visual Studio 的自动格式化中换行和换行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14043776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 10:30:50  来源:igfitidea点击:

Break lines and wrapping in auto formatting of Visual Studio with ReSharper

c#.netvisual-studioarchitectureresharper

提问by Felipe Oriani

I'm working in a C# project and using Visual Studio 2012. When Visual Studio tries to format my code, it breaks lines and make my code look difficult to read. The original code (what looks pretty nice to read for me and my team):

我在 C# 项目中工作并使用 Visual Studio 2012。当 Visual Studio 尝试格式化我的代码时,它会断行并使我的代码看起来难以阅读。原始代码(对我和我的团队来说看起来很不错):

if (list.Any(x => x.Type == (int) EnumType.Customer))
{

}

And when Visual Studio tries to format:

当 Visual Studio 尝试格式化时:

if (
    list.Any(
        x => x.Type ==
                (int) EnumType.Customer))
{
  // Other break codes
}

There are a lot of other parts where it is breaking my code. I like auto formatting for some parts, but my question is: Is there a way to disable this break lines from auto formatting in Visual Studio?*

还有很多其他部分破坏了我的代码。我喜欢某些部分的自动格式化,但我的问题是:有没有办法在 Visual Studio 中从自动格式化中禁用此断行?*

PS: I also have ReSharper installed.

PS:我也安装了 ReSharper。

采纳答案by Felipe Oriani

Solution for long lines:

长线解决方案:

ReSharper, menu OptionsCode EditingC#Formatting StyleLine Breaks And Wrapping.

ReSharper,菜单OptionsCode EditingC#Formatting StyleLine Breaks And Wrapping

And disable Wrap long lines:

并禁用Wrap long lines

Enter image description here

在此处输入图片说明

And it really makes me crazy!

这真的让我发疯!

回答by Adam Maras

In ReSharper's settings, in the Languagessection, you can change the formatting style of your C# code. The option you're looking to disable is something along the lines of "Indent anonymous method body." You can also look through the options to further customize the formatting style to your preference.

在 ReSharper 的设置中,在语言部分,您可以更改 C# 代码的格式样式。您要禁用的选项类似于“缩进匿名方法主体”。您还可以查看选项以根据您的喜好进一步自定义格式样式。