【问题标题】:Is there way to define required class members order in the .editorconfig file?有没有办法在 .editorconfig 文件中定义所需的类成员顺序?
【发布时间】:2021-05-24 17:32:18
【问题描述】:

我使用 .editorconfig 文件在我的 .Net 5 解决方案中定义代码样式规则。是否可以在.editorconfig 中定义所需的类成员顺序?例如,公共成员应该出现在私有之前,非静态成员应该出现在静态之前,方法应该出现在属性之前。

【问题讨论】:

    标签: c# .net-5 static-code-analysis editorconfig


    【解决方案1】:

    是的,例如

    csharp_preferred_modifier_order = public,private,protected,internal,static
    

    同时检查https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options

    认为在所有静态方法中,再次应用相同的顺序。

    【讨论】:

    【解决方案2】:

    您无法使用editorconfig 定义类中成员的顺序,但您可以使用 Roslyn 编写自定义分析器或使用 VS2019 的 CodeMaid 扩展,不确定 VSCode 扩展

    【讨论】:

      猜你喜欢
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 2010-12-07
      • 2021-07-24
      • 1970-01-01
      • 1970-01-01
      • 2019-04-17
      • 1970-01-01
      相关资源
      最近更新 更多