modern-csharp-coding-standards
Modern C# coding standards covering records, pattern matching, value objects, async/await, and high-performance patterns.
- Use
recordtypes for immutable DTOs and domain entities;readonly record structfor value objects with zero-allocation semantics - Leverage pattern matching with switch expressions, nullable reference types, and composition over inheritance for cleaner, type-safe code
- Apply async/await throughout with mandatory
CancellationTokenparameters; useSpan<T>,Memory<T>, andArrayPool<T>for performance-critical paths - Handle expected business errors with
Result<T, TError>types; reserve exceptions for unexpected system failures - Avoid reflection-based metaprogramming (AutoMapper, Mapster) in favor of explicit mapping and composition patterns
Modern C# Coding Standards
When to Use This Skill
Use this skill when:
- Writing new C# code or refactoring existing code
- Designing public APIs for libraries or services
- Optimizing performance-critical code paths
- Implementing domain models with strong typing
- Building async/await-heavy applications
- Working with binary data, buffers, or high-throughput scenarios
Reference Files
- value-objects-and-patterns.md: Full value object examples and pattern matching code
- performance-and-api-design.md: Span/Memory examples and API design principles
- composition-and-error-handling.md: Composition over inheritance, Result type, testing patterns
- anti-patterns-and-reflection.md: Reflection avoidance and common anti-patterns
More from aaronontheweb/dotnet-skills
efcore-patterns
Entity Framework Core best practices including NoTracking by default, query splitting for navigation collections, migration management, dedicated migration services, and common pitfalls to avoid.
977csharp-concurrency-patterns
Choosing the right concurrency abstraction in .NET - from async/await for I/O to Channels for producer/consumer to Akka.NET for stateful entity management. Avoid locks and manual synchronization unless absolutely necessary.
967dotnet-project-structure
Modern .NET project structure including .slnx solution format, Directory.Build.props, central package management, SourceLink, version management with RELEASE_NOTES.md, and SDK pinning with global.json.
272api-design
Design stable, compatible public APIs using extend-only design principles. Manage API compatibility, wire compatibility, and versioning for NuGet packages and distributed systems.
263type-design-performance
Design .NET types for performance. Seal classes, use readonly structs, prefer static pure functions, avoid premature enumeration, and choose the right collection types.
262dependency-injection-patterns
Organize DI registrations using IServiceCollection extension methods. Group related services into composable Add* methods for clean Program.cs and reusable configuration in tests.
257