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.
-
Tools from JetBrains can make this standard compatible with any version of .NET and Visual Studio ( ReSharper/ Rider).
-
Analyzers can be enabled in versions of .NET prior to 5.
-
Versions of Visual Studio prior to 2017 can use an extension.
-
For VS Code, the C# (powered by OmniSharp) extension will automatically use any
.editorconfig
in the top level of the workspace.
Exceptions to the Standard
None. Exceptions that would benefit a specific project should be documented along with a rationale for the exception.
Recommended Reading
-
For an introductory article on how to structure and format C# code see C# Coding Conventions (C# Programming Guide).
-
Design principles (SOLID). SOLID is a mnemonic acronym for five design principles intended to make software designs more understandable, flexible and maintainable.
-
Recommended Reading: Adaptive Code via C#
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
{
}