modern-csharp-coding-standards

Write modern C# code using records, pattern matching, Span<T>, and async best practices.

Updated May 22, 2026
One-click install
npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill modern-csharp-coding-standards-viniciuscs84
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: modern-csharp-coding-standards
Source: https://github.com/viniciuscs84/sdd-toolkit/tree/main/skills/modern-csharp-coding-standards
Command: npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill modern-csharp-coding-standards-viniciuscs84

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Inconsistent C# codebases accumulate technical debt through mutable DTOs, deep inheritance hierarchies, blocking async calls, and reflection-based mapping that fails at runtime. This Skill provides a complete, opinionated coding standard for C# 12+ so teams write uniform, performant, type-safe code from the start. ## Core Features & Use Cases - Modern Language Patterns: Enforces records for immutable data, readonly record structs for value objects, switch expressions, nullable reference types, and file-scoped namespaces. - Performance Guidance: Covers async/await best practices, CancellationToken conventions, Span<T>/Memory<T> zero-allocation patterns, and ArrayPool usage for high-throughput code. - API Design & Error Handling: Defines accept-abstractions/return-specific signatures, Result<T, TError> railway-oriented error handling, and explicit mapping methods instead of AutoMapper. - Use Case: When refactoring a legacy service, apply this Skill to convert mutable DTO classes into records, replace .Result blocking calls with async all the way, and swap AutoMapper profiles for compile-time-checked extension methods. ## Quick Start Ask the AI to write or refactor a C# class following the modern C# coding standards skill, for example to convert an order service to use records, pattern matching, and proper CancellationToken support.

Frequently Asked Questions about modern-csharp-coding-standards

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write modern C# code with records and pattern matching?

Use record types for DTOs and domain entities, readonly record struct for value objects, and switch expressions with property and relational patterns for branching logic. Enable nullable reference types and file-scoped namespaces for cleaner, type-safe code.

Should I use AutoMapper for DTO mapping in C#?

No. Reflection-based mappers like AutoMapper fail silently at runtime when property names or types mismatch. Use explicit extension methods like ToDto() instead, which give compile-time safety, easy debugging, and correct refactoring support.

When should I use Span<T> versus Memory<T> in C#?

Use Span<T> for synchronous, zero-allocation operations on buffers and string slicing. Use Memory<T> when data must cross await boundaries, since Span<T> cannot be used in async methods. Rent large temporary buffers from ArrayPool<T>.

Should C# value objects be classes or structs?

Value objects should be readonly record struct types. This gives value-based equality, stack allocation without GC pressure, and immutability. Avoid implicit conversion operators, since they defeat compile-time type safety at API boundaries.

Why does blocking on async code cause deadlocks in C#?

Calling .Result or .Wait() on a Task blocks the thread while the continuation needs that same thread to complete, causing deadlock. Use async all the way, accept CancellationToken parameters, and apply ConfigureAwait(false) in library code.

When should I use Result types instead of exceptions in C#?

Use Result<T, TError> for expected errors like validation failures, business rule violations, and not-found cases. Reserve exceptions for unexpected failures such as network errors or programming bugs. Pattern match on the Result to map errors to responses.