Aristokratos.CodeFormatter 1.0.1

dotnet add package Aristokratos.CodeFormatter --version 1.0.1
                    
NuGet\Install-Package Aristokratos.CodeFormatter -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aristokratos.CodeFormatter" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aristokratos.CodeFormatter" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Aristokratos.CodeFormatter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Aristokratos.CodeFormatter --version 1.0.1
                    
#r "nuget: Aristokratos.CodeFormatter, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Aristokratos.CodeFormatter@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Aristokratos.CodeFormatter&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Aristokratos.CodeFormatter&version=1.0.1
                    
Install as a Cake Tool

Aristokratos Code Formatter

A Roslyn-based code analyzer and formatter that helps organize your C# code by:

  • Organizing using statements in a pyramid format (shortest to longest)
  • Adding regions to class members for better code structure
  • Grouping members by type (Fields, Events, Properties, Constructors, Methods, Operators)

Installation

Install the NuGet package in your C# project:

<PackageReference Include="Aristokratos.CodeFormatter" Version="1.0.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

Or via Package Manager Console:

Install-Package Aristokratos.CodeFormatter

Features

Using Statement Organization

Automatically organizes using statements in pyramid format:

Before:

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TaskTracker.Application.Common.Models;
using TaskTracker.Application.Services.Interfaces;

After:

using Microsoft.AspNetCore.Mvc;
using TaskTracker.Application.Common.Models;
using Microsoft.AspNetCore.Authorization;
using TaskTracker.Application.Services.Interfaces;

Region Organization

Automatically adds regions to organize class members:

Before:

public class MyService
{
    private readonly ILogger _logger;
    public event EventHandler SomethingChanged;
    public string Name { get; set; }
    public MyService(ILogger logger) { _logger = logger; }
    public void DoSomething() { }
    private void HelperMethod() { }
}

After:

public class MyService
{
    #region Fields
    private readonly ILogger _logger;
    #endregion

    #region Events
    public event EventHandler SomethingChanged;
    #endregion

    #region Properties
    public string Name { get; set; }
    #endregion

    #region Constructors
    public MyService(ILogger logger) { _logger = logger; }
    #endregion

    #region Public Methods
    public void DoSomething() { }
    #endregion

    #region Private Methods
    private void HelperMethod() { }
    #endregion
}

How It Works

The analyzer provides two main diagnostic rules:

  • CF0001: Suggests organizing using statements and adding regions
  • CF0002: Identifies unused using statements

When you see these diagnostics in your IDE, you can:

  1. Use the light bulb actions (Ctrl+.) to apply fixes automatically
  2. Right-click and select "Fix all occurrences" to fix multiple issues at once

Supported IDEs

  • Visual Studio 2019 and later
  • Visual Studio Code with C# extension
  • JetBrains Rider
  • Any IDE that supports Roslyn analyzers

Configuration

The analyzer works out of the box with no configuration required. However, you can customize the severity levels in your .editorconfig:

[*.cs]
# Set diagnostic severity levels
dotnet_analyzer_diagnostic.CF0001.severity = suggestion
dotnet_analyzer_diagnostic.CF0002.severity = info

Version History

1.0.1

  • Fixed event handling in region organization
  • Improved using statement spacing
  • Enhanced pyramid sorting logic
  • Better handling of edge cases

1.0.0

  • Initial release
  • Basic using statement organization
  • Region-based class member organization

Contributing

Contributions are welcome! Please visit the GitHub repository to:

  • Report issues
  • Submit feature requests
  • Contribute code improvements

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions, please:

  1. Check the GitHub Issues
  2. Create a new issue if your problem isn't already reported
  3. Provide sample code that demonstrates the issue
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 210 8/24/2025
1.0.0 72 8/23/2025

Version 1.0.1: Fixed event handling in region organization, improved using statement spacing, and enhanced pyramid sorting logic.