regions - Region Count
The regions command counts all #region directives in C# files within a project or directory and reports the total. Use it to measure the prevalence of region usage before deciding whether to run nmbl endregions to remove them.
nmbl regions <ProjectFileOrDirectory>
ProjectFileOrDirectory- Path to a.csprojfile, a project directory, or.for the current directory.
Prints a single line with the total count of #region directives found:
Total Regions Found: 14
When no C# files are found, prints:
No C# files found in the specified project or directory.
Total Regions Found: 0
0- Success, including when no C# files or regions are found.1- The required path argument is missing or an unexpected error occurs.
nmbl regions src/MyProject/MyProject.csproj
nmbl regions src/
Recursively counts regions in all C# files under src/.
# See how many regions exist
nmbl regions src/
# If the count is acceptable, remove them
nmbl endregions src/ -y
# Before cleanup
nmbl regions src/ > metrics/regions-before.txt
# After removing regions
nmbl regions src/ > metrics/regions-after.txt
diff metrics/regions-before.txt metrics/regions-after.txt
Regions can indicate:
- Files that are too large — if you need regions to organize a file, the file may be doing too much.
- Multiple responsibilities — different regions often represent different concerns that belong in separate classes.
- Hidden complexity — collapsed regions make it harder to see the full structure of the code.
When you find files with many regions:
- Consider splitting the file — each region might become its own class.
- Use folders and namespaces — organize by namespace and folder structure instead.
- Apply design patterns — replace region-separated responsibilities with proper object-oriented design.
public class OrderService
{
#region Validation
// validation methods
#endregion
#region Processing
// processing methods
#endregion
}
public class OrderValidator { }
public class OrderProcessor { }
public class OrderService
{
private readonly OrderValidator _validator;
private readonly OrderProcessor _processor;
}
endregions- Remove region directivescc- Find complex methodscogc- Find hard-to-understand codeloc- Find large files