csharp-coding-standards

Codify modern C# coding standards for high-performance backend services.

3|Updated Jan 24, 2024
One-click install
npx skills add https://github.com/akoken/dotfiles --skill csharp-coding-standards
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-coding-standards
Source: https://github.com/akoken/dotfiles/tree/main/config/.copilot/skills/csharp-coding-standards
Command: npx skills add https://github.com/akoken/dotfiles --skill csharp-coding-standards

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a cohesive, opinionated set of guidelines for writing modern, high-performance C# code to ensure consistency across teams.

Core Features & Use Cases

  • Immutability by default using record types and init-only properties to model data safely.
  • Value objects as readonly record structs with explicit conversions to preserve value semantics and performance.
  • Modern pattern matching and API-design practices that emphasize composition over inheritance and clear boundaries.
  • Async-first design with CancellationToken awareness, ValueTask usage where appropriate, and zero-allocation patterns via Span<T> and Memory<T>.

Quick Start

  • Start by enabling nullable reference types and adopting records for DTOs and messages.
  • Introduce readonly record structs for value objects, and replace mutable types with immutable equivalents.
  • Apply composition-based designs (interfaces + small, focused components) over inheritance to build robust APIs.

Frequently Asked Questions about csharp-coding-standards

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

FAQPage Schema
How do I enforce immutability for DTOs and value objects in modern C#?

Enforce immutability in modern C# by using record types with init-only properties for DTOs, and readonly record structs for value objects to preserve value semantics and performance. This approach models data safely across backend services.

What's the best way to design high-performance, zero-allocation async C# APIs?

Design high-performance async C# APIs by adopting async-first patterns with CancellationToken awareness, using ValueTask where appropriate, and applying zero-allocation techniques via Span<T> and Memory<T> to minimize garbage collection overhead.

When do I need Span<T> and Memory<T> in C# backend services?

You need Span<T> and Memory<T> in C# backend services when processing large data buffers or implementing zero-allocation techniques to achieve high performance. They enable safe memory handling without creating unnecessary garbage collection pressure.

How does modern C# pattern matching improve API design and maintainability?

Modern C# pattern matching improves API design by emphasizing composition over inheritance and establishing clear boundaries. This approach shapes robust, maintainable APIs by replacing complex conditional logic with expressive, type-safe pattern matching.

Can I use readonly record structs for value objects instead of classes in C#?

Yes, you can use readonly record structs for value objects in C# to preserve value semantics and enhance performance. This modern standard replaces mutable types with immutable equivalents, ensuring explicit conversions and safe data modeling.

What C# coding standards should I adopt for consistent library and API development?

Adopt C# coding standards that enforce nullable reference types, immutability by default, composition over inheritance, and async-first design with zero-allocation patterns. These guidelines ensure consistency and robustness across backend services and libraries.