Resharper C#格式化样式在切断长行时在新行上显示"新"而不是相同的行

Tod*_*son 8 c# resharper code-formatting

因此Resharper在我的代码中的"new"之前放置一个换行符,重新格式化如下:

var foo = new Foo
{
    Bar = null,
    Baz =
        new Baz
        {
            Bap = null,
            Bork = null,
            Help =
                new PweaseHelp
                {
                    Korben = null,
                    Dallas = null,
                    Multipass = null
                },
            Me =
                new ClearlyMyAbilityToUnderstandResharperSettingsIs(
                    null),
        }
};
Run Code Online (Sandbox Code Playgroud)

但我真的很喜欢这样做:

var foo = new Foo
{
    Bar = null,
    Baz = new Baz
    {
        Bap = null,
        Bork = null,
        Help = new PweaseHelp
        {
            Korben = null,
            Dallas = null,
            Multipass = null
        },
        Me = new ClearlyMyAbilityToUnderstandResharperSettingsIs(null),
    }
};
Run Code Online (Sandbox Code Playgroud)

虽然我已经在我的.DotSettings文件中设置了所有设置,但我无法解决导致它的问题,我已经钻研了...任何帮助都会非常感激:)

编辑2(更新)

以下R#设置似乎让我接近我列出的内容,除非你为"wrap invocation arguments"选择"chop always",否则你仍然会看到之后的新行等于sign(带有列出的配置)和"包装对象和集合初始化程序"(由克里斯蒂安建议).

"总是剁"的问题是你会有非常短的方法调用和对象/集合初始化器也一直在切,这看起来很糟糕,所以我认为我们想要的是:

不要在方法调用/对象/集合初始化器的等号后面添加新行(但我无法在任何地方找到该设置,因此它可能是R#的错误或功能).

我会尝试在R#论坛/支持上提出它并报告我的发现.

<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARRAY_AND_OBJECT_INITIALIZER/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue">NEXT_LINE</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/CASE_BLOCK_BRACES/@EntryValue">NEXT_LINE</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/CONTINUOUS_INDENT_MULTIPLIER/@EntryValue">1</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EMPTY_BLOCK_STYLE/@EntryValue">TOGETHER_SAME_LINE</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_ANONYMOUS_METHOD_BLOCK/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INITIALIZER_BRACES/@EntryValue">NEXT_LINE</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_CODE/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_TRAILING_COMMENT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARGUMENTS_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">150</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_OBJECT_AND_COLLECTION_INITIALIZER_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_PARAMETERS_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
Run Code Online (Sandbox Code Playgroud)

khe*_*ang 5

如果您使用的是R#7.1,可能是由于新的代码格式改进.在R#选项下可以轻松配置所有这些行为:

Resharper C#格式化风格

编辑:使用我的设置,我最接近您建议的解决方案是将Wrap对象和集合初始化器设置为Chop,但是,由于某种原因,它忽略了Braces布局下的"Array and object initializer"设置并放置在同一行打开大括号,像这样:

var foo = new Foo {
    Bar = null,
    Baz = new Baz {
        Bap = null,
        Bork = null,
        Help = new PweaseHelp {
            Korben = null,
            Dallas = null,
            Multipass = null
        },
        Me = new ClearlyMyAbilityToUnderstandResharperSettingsIs(null),
    }
};
Run Code Online (Sandbox Code Playgroud)

它可能是我有一些其他设置导致这个,但对我来说这看起来像是有问题.也许你应该联系ReSharper支持并让他们看看它......