因此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),
}
};
但我真的很喜欢这样做:
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),
}
};
我已经钻研了我在.DotSettings文件中的所有设置,而且我无法解决导致它的问题...任何帮助都会非常感激:)
编辑2(更新)
以下R#设置似乎让我接近我列出的内容,除非你选择“chop always”for“wrap”,否则你仍会看到之后的新行等于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>
答案 0 :(得分:5)
如果您使用的是R#7.1,可能是由于新的Code Formatting Improvements。在R#选项下可以轻松配置所有这些行为:
编辑:根据我的设置,我最接近您建议的解决方案是将包装对象和集合初始化程序设置为 Chop始终 ,但是,由于某种原因,它忽略了大括号布局下的“数组和对象初始化程序”设置,并将左大括号放在同一行上,如下所示:
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),
}
};
可能是我有一些其他的设置导致了这个,但对我来说这看起来像是有问题的。也许你应该联系ReSharper Support并让他们看一下......