Skip to content

no-region-in-body

C#styleno fixdefault: offcsharp/stylecop

Reports a #region inside a block (a method, accessor or lambda body, or any block in one). Regions belong between members. No fix.

A region in a body splits one piece of logic with a fold that hides the middle of it. A body that needs sections is a body that should be split into methods.

To fix, extract the section into a method and delete the region.

Reported
...
namespace N { class Other { void M() {
#region R
#endregion
...
csharp:
lint:
rules:
no-region-in-body: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line no-region-in-body in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1123 full