Visual Studio-Resharper-Stylecop:如何摆脱 属性 值的缩进?

Visual Studio-Resharper-Stylecop: How to get rid of the indent for property values?

使用 Visual Studio、Resharper 和 StyleCop 扩展,在设置属性值时,我总是会像下面的示例一样格式化属性。

提示:请不要重构该代码。这样显式格式化是为了展示效果!

private ObservableCollection<DayOfWeek> WeekDays { get; } = new ObservableCollection<DayOfWeek>
                                                            {
                                                                DayOfWeek.Monday,
                                                                DayOfWeek.Tuesday,
                                                                DayOfWeek.Wednesday,
                                                                DayOfWeek.Thursday,
                                                                DayOfWeek.Friday,
                                                                DayOfWeek.Saturday,
                                                                DayOfWeek.Sunday
                                                            };

然而,这对我来说真的很难看。我如何告诉 Resharper / StyleCop 仅使用 4 个空格/1 个制表符缩进?

下面的示例显示了所需的结果:

private ObservableCollection<DayOfWeek> WeekDays { get; } = new ObservableCollection<DayOfWeek>
{
    DayOfWeek.Monday,
    DayOfWeek.Tuesday,
    DayOfWeek.Wednesday,
    DayOfWeek.Thursday,
    DayOfWeek.Friday,
    DayOfWeek.Saturday,
    DayOfWeek.Sunday
};

您需要关闭 "Align Multiline Constructs" 部分中名为 "Array, object and collection initializer" 的设置。只需将该名称粘贴到 ReSharper 选项对话框左上角的搜索框中。

要自己发现影响您的代码段的设置,您可以使用 "Configure formatting" 功能。 Select 有问题的代码,Alt-Enter > 格式选择 > 配置...