csharp-conventions
C# code conventions covering .NET 8+/C# 12, nullable reference types, Roslyn analyzers, xUnit, record types, async/await discipline, and dependency security. Load when writing or reviewing C# code.
SKILL.mdinternal/builtins/languages/csharp/skills/csharp-conventions/SKILL.md
GitHub- .NET 8+ C# 12, file-scoped namespaces, primary constructors,
<Nullable>enable</Nullable>. - Formatting:
dotnet format+ Roslyn analyzers,<TreatWarningsAsErrors>true</TreatWarningsAsErrors>. - Style enforcement:
.editorconfigfor consistent rules across team. Use an analyzer set (e.g., StyleCop.Analyzers or Roslynator). - Testing: xUnit with
[Theory]/[InlineData], an assertion library (e.g., FluentAssertions), a coverage tool (e.g., coverlet) at 80%+. - Benchmarking: a benchmark harness (e.g., BenchmarkDotNet) for performance testing — never
Stopwatchloops. recordtypes for immutable data,requiredproperties, pattern matching in switch expressions.- Async:
async/awaitthroughout — never.Resultor.Wait(),ValueTaskfor hot paths, avoid deadlocks. - Security:
dotnet list package --vulnerablefor CVE scanning. Zero tolerance for critical/high. - Dependencies: NuGet
PackageReference, commitpackages.lock.json,Directory.Build.propsfor shared config. - Collection expressions (
[1, 2, 3]),requiredmodifier, raw string literals for multi-line. - Anti-patterns:
dynamic,objectparams, unguardedcatch (Exception),#pragma warning disable.