Resharper 可以对枚举进行特殊设置吗?

发布于 2024-10-10 21:35:18 字数 905 浏览 5 评论 0原文

我正在使用 Resharper 5.1.1 重新格式化我的代码(清理代码、Ctrl+E、Ctrl+C)。我无法让它按照我想要的方式格式化我的代码。我希望我的代码如下所示:

public class Person
{
    public enum Sex {Male, Female}

    public Sex Gender { get; set; }

    public Person(Sex gender)
    {
        Gender = gender;
    }
}

我的问题出在 enum 上。由于枚举是一种类型,就像类是一种类型一样,因此它们的处理方式相同。因此,枚举的格式为:

public enum Sex
{
    Male,
    Female
}

类型的大括号(即enum)放置在单独的行上,并且成员也放置在单独的行上。对于一个正是我想要的班级。但对于(简单的)enum 我只想将它们放在一行上。

对于自动属性有一个例外(将抽象属性/索引器/事件声明放在单行上),因此自动属性按照我想要的方式格式化。

Resharper 中是否有一个选项可以将枚举放在一行上?

更新Resharper 论坛 上发布相同的问题后,我被告知目前不可能。已为其创建功能请求。如果您还认为这是您希望在 Resharper 的未来版本中看到的选项,请投票支持该请求。

I'm using Resharper 5.1.1 to reformat my code (Cleanup Code, Ctrl+E, Ctrl+C). I can't get it to format my code the way I want it to. I want my code to look like this:

public class Person
{
    public enum Sex {Male, Female}

    public Sex Gender { get; set; }

    public Person(Sex gender)
    {
        Gender = gender;
    }
}

My problem is with the enum. Since an enum is a type, just as a class is a type, they are treated the same. Therefor, the enum is formatted as

public enum Sex
{
    Male,
    Female
}

The curly braces of the type (i.e. the enum) are placed on a separate line and the members are also placed on a separate line. For a Class that is exactly what I want. But for a (simple) enum I just want them on a single line.

For an auto property there is an exception (Place abstract property/indexer/event declaration on single line), so the auto property is formatted the way I want it to.

Is there an option in Resharper to have it place an enum on a single line?

Update
After posting the same question on the Resharper forum, I've been told it currently isn't possible. A Feature Request has been created for it. If you also feel this is an option you'd like to see in a future version of Resharper, please vote for the request.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若水般的淡然安静女子 2024-10-17 21:35:19

查看了 ReSharper 的选项,我也没有发现任何选项。

也许如果您在 ReSharper 论坛 中发布问题,您可以得到其开发人员的直接回复,或者支持工程师。

Taking a look at the options of ReSharper, I found no option, too.

Maybe if you post the question in the ReSharper forum you can get direct response from their developers or support engineers.

尐籹人 2024-10-17 21:35:19

老问题,但答案已经改变。

在带有 Resharper 2019.1.1(可能还有旧版本)的 Visual Studio 2019 中,您可以在以下位置配置枚举的换行符:

Extensions > ReSharper>选项...>>代码编辑> C#>格式样式>换行和换行>枚举的排列

Old question but the answer has changed.

In Visual Studio 2019 with Resharper 2019.1.1 (and probably in older ones) you can configure line breaks of enums in:

Extensions > ReSharper > Options... > Code Editing > C# > Formatting Style > Line Breaks and Wrapping > Arrangement of Enumerations

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文