Create the Business Case, Stakeholder Analysis (S01 course participant, S02 Udemy coursists, S03 GitHub viewers), Project Plan and the milestone documents MIL-001 (project setup, 6 tasks) and MIL-002 (game implementation, 8 tasks) for the console Blackjack game. Register PP and MIL in the artifact registry, set the PO language to en, and link the synced Gitea milestones in the Gateway Schedule. Refs #1 Refs #2 Refs #3 Refs #4 Refs #5 Refs #6 Refs #7 Refs #8 Refs #9 Refs #10 Refs #11 Refs #12 Refs #13 Refs #14
3.0 KiB
3.0 KiB
C# conventions
Standard base
Microsoft's C# coding conventions and .NET Framework Design Guidelines, with
the analyzers that ship in the SDK. Target the language version of the
project's LangVersion / target framework.
Naming
| Element | Convention | Example |
|---|---|---|
| Namespace | PascalCase, matches folder path |
Billing.Stays |
| Class, struct, record, enum, delegate | PascalCase (nouns) |
StayReader |
| Interface | I + PascalCase |
IStayReader |
| Method, property, event, public field | PascalCase |
ReadStays(), CheckIn |
Constant, static readonly |
PascalCase |
MaxRetries |
| Enum value | PascalCase; [Flags] enums are plural |
Status.NotFound |
| Parameter, local variable | camelCase |
byteCount |
| Private / internal field | _camelCase |
_buffer |
| Generic type parameter | T or T + PascalCase |
T, TKey |
| Async method | ends in Async |
ReadStaysAsync() |
| Exception, attribute | end in Exception / Attribute |
InvalidDateException |
| Boolean | Is, Has, Can prefix |
IsActive |
| File | the type's name, one top-level type per file | StayReader.cs |
- Two-letter acronyms are upper case (
IO); longer ones arePascalCase(Xml,Http).
Formatting
.editorconfigchecked in;dotnet formatapplies it. 4 spaces, Allman braces, braces on every control-flow body.- File-scoped namespaces (
namespace X;);usingdirectives outside the namespace,Systemfirst. varwhen the type is obvious from the right-hand side, explicit type otherwise.
Language rules
- Enable nullable reference types (
<Nullable>enable</Nullable>) and treat nullable warnings as errors; do not suppress with!without a comment. IDisposableowners useusing; implement the dispose pattern only when needed.async/awaitall the way; no.Resultor.Wait(); noasync voidexcept event handlers; passCancellationTokenthrough public async APIs.- Prefer properties over public fields,
readonlyandinitfor immutability,recordfor value-like data, pattern matching and switch expressions over longifchains. - LINQ for queries, loops for side effects; do not enumerate a sequence twice.
- String interpolation over concatenation;
StringBuilderin loops;DateTimeOffsetoverDateTimefor points in time;decimalfor money. - XML documentation comments (
///) on public types and members.
Errors
Throw specific exceptions (ArgumentNullException, custom types); validate
arguments at the public boundary (ArgumentNullException.ThrowIfNull). Catch
the narrowest type; throw; (not throw ex;) to rethrow. Never an empty
catch.
Tests
xUnit, NUnit or MSTest; names like Method_Condition_Expected; one behaviour
per test; no dependence on order, time or the network.
Tooling
dotnet format, the .NET analyzers (AnalysisLevel, EnforceCodeStyleInBuild)
and optionally StyleCop.Analyzers, configured in .editorconfig.
Review with QC-CS-001.