C# Code Style

Reference Code Standard

Follow Microsoft’s guidelines:

Microsoft has a default .editorconfig that matches their coding conventions.

External APIs shall use xmldoc. This allows OpenAPI (API documentation specification) implemented by Swashbuckle and tools like DocFX (MSDN style documentation tool) to create detailed documentation.

Implementing the Standard

Tools/Procedures Type Notes
Visual Studio Commercial Requires .NET 5 or higher and Visual Studio 2017 or higher
ReSharper Commercial IntelliSense Code Linter for C++ evaluates as you type
Visual Studio Code Free Formats source code according to style guide.
  • This standard requires .NET 5 or higher and Visual Studio 2017 or higher to run out of the box.

  • Download the dotnet/runtime .editorconfig file and place it in the same directory as your solution file (SLN).

-- Solution Root Folder
---- .editorconfig file
---- .sln file
-------- Subfolders/Projects
  • Change or remove license header
# License header
file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.

Exceptions to the Standard

None. Exceptions that would benefit a specific project should be documented along with a rationale for the exception.

Allowing Exceptions

If there needs to be an exception to the standard, it can be called out with a SuppressMessage attribute . This should be rarely needed. Example below:

[SuppressMessage("Performance", "CA1823:Avoid unused private fields")]
public class X
{

}