ReSharper的C#格式化风格表演及QUOT;新"新行而不是同一行斩波排长队时, [英] Resharper C# Formatting Style shows "new" on new line instead of same line when chopping long lines

查看:453
本文介绍了ReSharper的C#格式化风格表演及QUOT;新"新行而不是同一行斩波排长队时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以ReSharper的是把一个换行符前的新在我的代码重新格式化时,如下所示:

 无功富=新富
{
酒吧= NULL,
巴兹=
新巴兹
{
Bap的= NULL,
博克= NULL ,
帮助=
新PweaseHelp
{
Korben = NULL,
达拉斯= NULL,
多道= NULL
},
我=
新ClearlyMyAbilityToUnderstandResharperSettingsIs(
空),
}
};



但是我真的很喜欢它太做到这一点:

 无功富=新富
{
酒吧= NULL,
巴兹=新巴兹
{
Bap的= NULL,
博克= NULL,
说明=新PweaseHelp
{
Korben = NULL,
达拉斯= NULL,
多道= NULL
},
我=新ClearlyMyAbilityToUnderstandResharperSettingsIs(空),
}
};



我钻研虽然我在.DotSettings文件(县)的所有设置和我可以科技工作是什么原因造成它...任何帮助将是非常赞赏:)



编辑2(修订版)



下面是似乎让我接近我所列出的R·设置,你还是会看到新行,然后后等于号(与列出的配置),除非你选择斩始终以为包装调用参数和包装对象和集合初始化(由克里斯蒂安的建议)。



与砍总是问题是,你必须非常短的方法调用和对象/集合初始化也砍所有的时间,这很糟糕,所以我觉得我们要的是:



唐'T换上新行后等号方法调用/对象/集合初始化的(但我找不到任何地方的设置,所以它可能是一个错误或R·功能)。



我会尽力提高它在R#论坛/支持和汇报我的发现。

 < S:布尔X:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / ALIGN_MULTILINE_ARRAY_AND_OBJECT_INITIALIZER / @ EntryValue>假LT; / S:布尔> 
< S:字符串x:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / ANONYMOUS_METHOD_DECLARATION_BRACES / @ EntryValue> NEXT_LINE< / S:字符串>
< S:字符串x:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / CASE_BLOCK_BRACES / @ EntryValue> NEXT_LINE< / S:字符串>
< S:Int64的X:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / CONTINUOUS_INDENT_MULTIPLIER / @ EntryValue> 1 LT; / S的Int64>
< S:字符串x:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / EMPTY_BLOCK_STYLE / @ EntryValue> TOGETHER_SAME_LINE< / S:字符串>
< S:布尔X:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / INDENT_ANONYMOUS_METHOD_BLOCK / @ EntryValue>真< / S:布尔>
< S:字符串x:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / INITIALIZER_BRACES / @ EntryValue> NEXT_LINE< / S:字符串>
< S:Int64的X:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / KEEP_BLANK_LINES_IN_CODE / @ EntryValue> 1 LT; / S的Int64>
< S:Int64的X:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / KEEP_BLANK_LINES_IN_DECLARATIONS / @ EntryValue> 1 LT; / S的Int64>
< S:布尔X:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / LINE_FEED_AT_FILE_END / @ EntryValue>真< / S:布尔>
< S:布尔X:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / SPACE_AFTER_TYPECAST_PARENTHESES / @ EntryValue>假LT; / S:布尔>
< S:布尔X:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / SPACE_BEFORE_TRAILING_COMMENT / @ EntryValue>真< / S:布尔>
< S:布尔X:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES / @ EntryValue>真< / S:布尔>
< S:字符串x:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / WRAP_ARGUMENTS_STYLE / @ EntryValue> CHOP_IF_LONG< / S:字符串>
< S:Int64的X:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / WRAP_LIMIT / @ EntryValue> 150℃/ S的Int64>
< S:字符串x:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / WRAP_OBJECT_AND_COLLECTION_INITIALIZER_STYLE / @ EntryValue> CHOP_IF_LONG< / S:字符串>
< S:字符串x:键=/默认/ CodeStyle / CodeFormatting / CSharpFormat / WRAP_PARAMETERS_STYLE / @ EntryValue> CHOP_IF_LONG< / S:字符串>


解决方案

如果您使用的是R·7.1它可能是由于新代码格式化改进 。所有这些行为可以容易下的R·选项进行配置:





编辑:使用我的设置,最接近我来你提出的解决方案是设置的裹对象和集合初始化的到的盖章总是的,但后来,由于某种原因,它忽略了的数组和对象初始值设定的根据设定的大括号的布局的并把左大括号放在同一行,像这样的:

  VAR富=新的Foo {
酒吧= NULL,
巴兹=新巴兹{
Bap的= NULL,
博克= NULL,
说明=新PweaseHelp {
Korben = NULL,
达拉斯= NULL,
多道= NULL
},
我=新ClearlyMyAbilityToUnderstandResharperSettingsIs(空),
}
};



这可能是一些其他的设置,我有,是造成这一点,但对我来说,这看起来像它的窃听。也许你应该与 ReSharper的支持,让他们看看吧...


So Resharper is putting a line break before the "new" in my code when re-formatting it as follows:

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),
        }
};

But I'd really like it too do this:

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),
    }
};

I've delved though all the settings I have in my .DotSettings file(s) and I can't work out what is causing it... Any help would be most appreciated :)

EDIT 2 (UPDATED)

Here are the R# settings that seem to be getting me close to what I have listed, you'll still see the new line after then equals sign (with the listed configuration) unless you select "chop always" for "wrap invocation arguments" and "wrap object and collection initializer" (as suggested by Kristian).

The problem with "chop always" is that you'll have really short method calls and object/collection initializers also chopping all the time, which looks bad, so I think what we want is:

Don't put a new line after the equals sign for method calls / object/collection initializers (but I can't find that setting anywhere, so it could be a bug or feature of R#).

I'll try to raise it on the R# forums / support and report back my findings.

<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>

解决方案

If you are using R# 7.1 it could be due to the new Code Formatting Improvements. All this behavior can easily be configured under R# options:

EDIT: With my settings, the closest I've come to your proposed solution is setting Wrap object and collection initializer to Chop always, but then, for some reason, it ignores the "Array and object initializer" setting under Braces layout and puts the opening brace on the same line, like this:

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),
    }
};

It could be some other settings I have that is causing this, but to me this looks like it's bugged. Maybe you should contact ReSharper Support and have them take a look at it...

这篇关于ReSharper的C#格式化风格表演及QUOT;新&QUOT;新行而不是同一行斩波排长队时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆