Aristokratos.CodeFormatter
1.0.1
dotnet add package Aristokratos.CodeFormatter --version 1.0.1
NuGet\Install-Package Aristokratos.CodeFormatter -Version 1.0.1
<PackageReference Include="Aristokratos.CodeFormatter" Version="1.0.1" />
<PackageVersion Include="Aristokratos.CodeFormatter" Version="1.0.1" />
<PackageReference Include="Aristokratos.CodeFormatter" />
paket add Aristokratos.CodeFormatter --version 1.0.1
#r "nuget: Aristokratos.CodeFormatter, 1.0.1"
#:package Aristokratos.CodeFormatter@1.0.1
#addin nuget:?package=Aristokratos.CodeFormatter&version=1.0.1
#tool nuget:?package=Aristokratos.CodeFormatter&version=1.0.1
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:
- Use the light bulb actions (Ctrl+.) to apply fixes automatically
- 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:
- Check the GitHub Issues
- Create a new issue if your problem isn't already reported
- Provide sample code that demonstrates the issue
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 1.0.1: Fixed event handling in region organization, improved using statement spacing, and enhanced pyramid sorting logic.