Reputation: 827
How to enforce ordering for a class file with resharper?
For example, I want to enforce all developers to use the following order of declaring variables / properties / methods
Private variables Protected variables Public variables Protected properties Public properties Public constructor Public methods etc.
Upvotes: 0
Views: 111
Reputation: 382
Resharper may help you to maintain order in the file, but cannot enforce this.
You may achieve your goal if you combine Resharper with code analysis tool, which will produce warnings if an order of class members is broken, and enabling 'Treat warnings as errors' setting (Right click on project > Properties > Build).
Take a look at Stylecop analyzers project: https://github.com/DotNetAnalyzers/StyleCopAnalyzers one of the stylecop rules enforces order and is configurable
Once you make your project failing because of incorrect ordering you may use Resharpers code clean-up 'Apply Layout'. Desired order of class members may be configured in C# > File Layout section of Resharper options
Upvotes: 1