EditorConfig
The project uses.editorconfig to maintain consistent coding styles:
.editorconfig
Automatic Formatting
dotnet format
The project usesdotnet format for automatic code formatting.
Run formatting manually:
IDE Integration
Visual Studio Code:- Install C# Dev Kit extension
- Format on save is configured in
.vscode/settings.json
- EditorConfig is automatically detected
- Use built-in formatter (Ctrl+K, Ctrl+D)
C# Coding Conventions
Naming Conventions
PascalCase
Use PascalCase for:- Classes
- Interfaces (with
Iprefix) - Methods
- Properties
- Events
- Enums and enum values
- Constants
camelCase
Use camelCase for:- Private fields (with
_prefix) - Method parameters
- Local variables
Interface Naming
Interfaces start withI:
Async Method Naming
Async methods end withAsync:
Code Organization
File-Scoped Namespaces
Use file-scoped namespaces (C# 10+):Using Directives
Sortusing directives with System.* first:
Member Ordering
Order class members:- Fields (private, then protected)
- Constructors
- Properties (public, then protected/private)
- Methods (public, then protected/private)
- Nested types
Language Features
var Keyword
Prefervar when the type is obvious:
String Interpolation
Use string interpolation over concatenation:Null Handling
Null-conditional operators:Pattern Matching
Use pattern matching where appropriate:Braces and Formatting
Brace Style
Always use braces, even for single-line statements:Line Length
Keep lines under 120 characters (guideline, not strict rule). Break long lines at logical points:Comments and Documentation
XML Documentation
Add XML comments for public APIs:Inline Comments
Use inline comments to explain “why”, not “what”:TODO Comments
Error Handling
Exceptions
Use specific exception types:Try-Catch
Catch specific exceptions when possible:Async/Await
Async All the Way
ConfigureAwait
Library code should useConfigureAwait(false) (though not strictly enforced):
LINQ and Collections
LINQ Style
Collection Initialization
Testing Code Style
Test Naming
Format:MethodName_Scenario_ExpectedOutcome
Arrange-Act-Assert
Always structure tests with clear AAA sections:Common Analyzer Rules
The project enforces several code analysis rules:CA1304 & CA1305: Specify CultureInfo
IDE0005: Remove Unnecessary Usings
CS8509: Missing Switch Case
See Also
- Contribution Guide - How to contribute
- Testing Guide - Testing standards
- EditorConfig Documentation