An unofficial bundle of formatting tools to enforce writing C# in the most conventional manner possible.
The package deviates from Microsoft's established conventions in several areas. For example,
_camelCase
for private fields.PreEvent
/PostEvent
orBeforeEvent
/AfterEvent
instead ofEventing
/Evented
.
Furthermore, the opinion of this package on some disputed C# conventions are as follows,
- Explicit type over var unless evident.
IEnumerable<string> x = GetNames(); var y = (string)obj; var z = new object(); object a = new(); int b = 2; var c = 3L;
- All methods must use block bodies, as opposed to expression bodies. However, properties may use either block bodies or expression bodies.
- All selective statements(if, switch), loop statements(while, for), and other similar statements must be accompanied by curly braces.
One notable exception is a series of using statements after another.
// Permitted using (null) using (null) using (null) { } // Permitted using (null) { using (null) { using (null) { } } }
- No parentheses or grouping constructs unless necessary.
- Switch case contents must be wrapped in {} and must have the break statement placed outside the curly braces if possible.
#§ Analyzers section
#¶ Analyzers subsection
#: Analyzer description
#> Link to documentation
#! Per-project configuration
#? Per-user configuration
#- Removed
#X Superseded by another analyzer
#/ Miscellaneous comment
Some common reasons for an analyzer to be disabled is as follows,
- Situational: the analyzer is sometimes useful and sometimes not.
- Subjective: the reported issue is decided by the opinions of the developer.
- Too broad: the analyzer reports too many false positives
- .NET SDK 8 or newer
- Locate the project file(for example,
Project.csproj
,Project.fsproj
). - Open the project file in an editor.
- Locate the an
<ItemGroup>
. - Add a new
PackageReference
element to the item group with theInclude
attribute set toBelp.Formatting
and theVersion
attribute set to0.0.1
or a version of choosing. For example,<PackageReference Include="Belp.Formatting" Version="0.0.1" />
. - Run
dotnet restore
.
- Locate the project file(for example,
Project.csproj
,Project.fsproj
). - Open the project file in an editor.
- Locate the
PackageReference
element with anInclude
attribute set toBelp.Formatting
. - Delete the element.
- Open a terminal.
- Navigate to the containing directory of the project file.
- Run the command
dotnet add package Belp.Formatting
.
- Open a terminal.
- Navigate to the containing directory of the project file.
- Run the command
dotnet remove package Belp.Formatting
.
- Open Visual Studio.
- Right click the project in the Solution Explorer.
- Click on "Manage NuGet Packages".
- Go to the "Browse" tab.
- Search for
Belp.Formatting
. - Install.
- Open Visual Studio.
- Right click the project in the Solution Explorer.
- Click on "Manage NuGet Packages".
- Go to the "Installed" tab.
- Click on
Belp.Formatting
. - Click on "Uninstall".
The package automatically configures the formatting upon installation.
- Install the .NET 8.0 SDK version 8.0.100 or newer.
- Open
Belp.Formatting.sln
. - Open the Solution Explorer.
- Right click on the project
Belp.Formatting
in the Solution Explorer. - Click on
Pack
.
- Open a terminal in the repository root.
- Run
dotnet pack
By default, the output is located in src/Belp.Formatting/Belp.Formatting/bin/Release/
.